Ich möchte ein String-Array-Nachkommen durch seine dritte Spalte in Abstieg sortieren, das Problem ist, dass ich nach seinem numerischen Wert sortieren möchte.Java sortiere Array durch das dritte Element
Beispiel:
Wenn ich dieses Array zunächst:
String [][] array = new String[][] {
{"Barcelona", "156", "1604"},
{"Girona", "256", "97"},
{"Tarragona", "91", "132"},
{"Saragossa", "140", "666"}
}
Ich will es, dies werden:
{
{"Barcelona", "156", "1604"},
{"Saragossa", "140", "666"},
{"Tarragona", "91", "132"},
{"Girona", "256", "97"}
}
Wie kann ich das tun?
Vielleicht Inspiration ziehen aus http://stackoverflow.com/questions/5805602/how-to-sort-list-of -objects-by-some-property –
'Arrays.sort (array, Comparator.comsparingInt ((String [] a) -> Ganzzahl.parseInt (a [2])). reversed()); ' – shmosel