I try to sort only a selected part of an array.
I have try this code:
public static void shortArray(String[][] array){
Arrays.sort(array, new Comparator<String[]>() {
@Override
public int compare(final String[] entry1, final String[] entry2) {
final float time1 = Float.parseFloat(entry1[1]);
final float time2 = Float.parseFloat(entry2[1]);
if (time2 > time1) {
return 1;
} else if (time2 == time1) {
return 0;
} else {
return -1;
}
}
});
}
but it sorts the entire array.
Is there any way to sort starting from a specific index?
Yes, by creating a list-view of the array (through
Arrays.asList), and by usinglist.subListandCollections.sortto sort a part of it.