How can i Sort a list of String array objects alphabetically.
I Set my List as follows:
List CurrentRankingsList = rankings.getRankings();
I have a List of String objects like this:
[["Dwayne","5"], ["Bill","4"], ["James","3"], ["Sally","3"]]
How can i sort this list by the Names, alphabetically whilst maintaining the List structure eg [["Bill","4"], ["Dwayne","5"], ["James","3"], ["Sally","3"]]
I've tried the following but list is not getting sorted correctly
(Updated code from original question )
Collections.sort(CurrentRankingsList, new Comparator<Rankable>()
{
@Override
public int compare(Rankable o1, Rankable o2) {
// TODO Auto-generated method stub
String testo1=o1.getObject().toString();
String testo2=o2.getObject().toString();
int x = o1.getObject().toString().compareTo(o2.getObject().toString());
return o1.getObject().toString().compareTo(o2.getObject().toString());
}
}) ;
On debugging the compare we get a Paul (o1.GetObject.ToString) vs Nathan(o2.GetObject.ToString)