public static Integer[] createSortedPermutation(int size,Comparator<Integer> comparator){
  Integer[] indexes=new Integer[size];
  for (int i=0; i < size; i++) {
    indexes[i]=i;
  }
  Arrays.sort(indexes,comparator);
  return indexes;
}

public static Integer [ ] createSortedPermutation ( int size , Comparator < Integer > comparator ) { Integer [ ] indexes = new Integer [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { indexes [ i ] = i ; } Arrays . sort ( indexes , comparator ) ; return indexes ; }
creates an array of integers of length " size " , in which each number from 0 to ( size - 1 ) occurs exactly once . the integers are sorted using the given comparator . this can be used to create a sorting for arrays that cannot be modified directly .
