If you are having a string arraylist which contains names of people and you want to sort the arraylist in alphabetical order than use the below code.
Sorting a ArrayList
Most easy method to do so is..using Collections .You can use Collections to perform sorting or any other function on ArrayList.
for example :
To sort an arraylist according to name:
Collections.sort(YourArrayList, new Comparator<String>() { @Override public int compare(String text1, String text2) { return text1.compareToIgnoreCase( text2); } });
Reverse a arraylist :
Collections.reverse(YourArrayList);
Most easy method to do so is..using Collections .You can use Collections to perform sorting or any other function on ArrayList.
for example :
To sort an arraylist according to name:
Collections.sort(YourArrayList, new Comparator<String>() { @Override public int compare(String text1, String text2) { return text1.compareToIgnoreCase( text2); } });
Reverse a arraylist :
Collections.reverse(YourArrayList);
0 comments:
Post a Comment