Q:

how to i fomat 4 digit in Arrays.sort(java)

I want to output the random number by 4 digit such as 1 = 0001 ,100=0100
but i use String.format i can't run:
Arrays.sort(array);

System.out.println(Arrays.toString(array));

A:

Try display the array one by one using for loop:
Random rand = new Random(); 

for (int i = 0; i < array.length; i++) 
    array[i] = rand.nextInt(9999);

Arrays.sort(array);

for (Integer s : array) {
       System.out.println(String.format("%04d", s));
    }

