in Android Code Tips

Android sorting an ArrayList

Title of my original article: How to sort an ArrayList in Java

Class Test {
public String name;
public String sirName;
}
ArrayList<Test> res = new ArrayList<Test>();
res.add(…);
res.add(…);
Comparator<Test> comperator = new Comparator<Test>() {
@Override
public int compare(Test object1, Test object2) {
return object1.name.compareToIgnoreCase(object2.name);
}
};
Collections.sort(res, comperator);
Share