- public class SleepSort {
- public static void main(String[] args) {
- int[] nums = new int[]{1, 2, 34, 4, 45, 56};
- sleepSort(nums);
- }
-
- public static void sleepSort(int[] nums) {
- for (int i = 0; i < nums.length; i++) {
- final int num = nums[i];
- new Thread(() -> {
- try {
- Thread.sleep(num);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println(num);
- }).start();
- }
- }
- }