My String array looks like String[][] cat = new String[13][4];
I want to sort all [13] by the 3rd value in the second column "[][2]".
int myNum = 0;
Arrays.sort(cat, new Comparator<String[]>() {
@Override
public int compare(final String[] entry1, final String[] entry2) {
final String e1 = entry1[1];
final String e2 = entry2[1];
return e1.compareTo(e2);
}
});
for (final String[] s : cat) {
System.out.println("SORTING: "+s[0] + " " + s[1]+ " " + s[2]+ " " + s[3]);
try {
myNum = Integer.parseInt(s[2]);
} catch (NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
if (myNum > 3 && s[1].equals("1")) {
moreValues2.add(s[1]);
moreURLS2.add(s[3]);
}
}
How do I choose what value to sort by. In my code above it is sorting by the first column but I wish to sort by the 3rd. I am not sure what to modify and why to modify it.
I read http://docs.oracle.com/javase/6/docs/api/java/util/Comparator.html to no avail.
and version 7