Created
August 11, 2014 10:30
-
-
Save Reacoder/edbb688c45e608465b8d to your computer and use it in GitHub Desktop.
From http://stackoverflow.com/questions/18441846/how-sort-a-arraylist-in-java how sort a ArrayList in java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Fruit> fruits= new ArrayList<Fruit>(); | |
Fruit fruit; | |
for(int i=0;i<100;i++) | |
{ | |
fruit = new fruit(); | |
fruit.setname(...); | |
fruits.add(fruit); | |
} | |
//Sorting | |
Collections.sort(fruits, new Comparator<Fruit>() { | |
@Override | |
public int compare(Fruit fruite1, Fruit fruite2) | |
{ | |
return fruite1.fruitName.compareTo(fruite2.fruitName); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment