I have a Java List<String[]> of objects like ["a", "b", "c", "d", "e"], ["f", "g", "h", "i", "j"],...
I need to sort this List by the way SQL does, ie, Order by Column2, Column4. I have beat my head against this for a good while and appreciate help. I am thick headed on this and need a clear example.
List<String[]> arraylistofStrings = loads1;
Collections.sort(arraylistofStrings,new java.util.Comparator<String[]>() {
public int compare(String[] strings, String[] otherStrings) {
//First followed by 2nd, 3rd and 4th
String _temp1 = strings[0] + "_" + strings[1]+ "_" + strings[2]+ "_" + strings[3];
String _temp2 = otherStrings[0] + "_" + otherStrings[1]+ "_" + otherStrings[2]+ "_" + otherStrings[3];
return _temp1.compareTo(_temp2);
}
});
for (String[] sa : arraylistofStrings) {
System.out.println(Arrays.toString(sa));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.