public static < T > void arrangeByIndex ( T [ ] array , Integer [ ] indexes ) { if ( array . length != indexes . length ) { throw new IllegalArgumentException ( "The length of the two arrays must match." ) ; } //sort the array based on the indexes for ( int i = 0 ; i < array . length ; i ++ ) { int index = indexes [ i ] ; //swap T tmp = array [ i ] ; array [ i ] = array [ index ] ; array [ index ] = tmp ; } }
Rearranges the array based on the order of the provided indexes .