Ventrix’s Code Folds

How to sort an ArrayList in Java

by ventrix on Sep.22, 2009, under android, java

Example:

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);

the list is now sorted by name.

:)

1 comment for this entry:
  1. jaipur

    a BIG BIG BIG thanks from germany :)

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...