fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13.  
  14. final Integer[] arr =
  15. { 12, 67, 1, 34, 9, 78, 6, 31 };
  16. final Integer[] perm = new Integer[arr.length];
  17. for (int i = 0 ; i != perm.length ; i++) {
  18. perm[i] = i;
  19. }
  20. Arrays.sort(perm, new Comparator<Integer>()
  21. {
  22. @Override
  23. public int compare(Integer x, Integer y)
  24. {
  25. return arr[x] - arr[y];
  26. }
  27. });
  28.  
  29. System.out.println("low to high:" + Arrays.toString(perm));
  30.  
  31. }
  32. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
low to high:[2, 6, 4, 0, 7, 3, 1, 5]