Sorting ArrayList
Ref :how-to-sort-an-arraylist-in-java
import java.util.ArrayList;
import java.util.Collections;
public class SortingArrayList {
public static void main(String args[]){
ArrayList<String> al = new ArrayList<String> ();
al.add("22");
al.add("33");
al.add("11");
al.add("cc");
al.add("bb");
al.add("aa");
System.out.println("Printing List before sorting......");
for(String value: al){
System.out.println(value);
}
//Sorting...
Collections.sort(al);
System.out.println("Printing List after sorting......");
for(String value: al){
System.out.println(value);
}
}
}
Output
Printing List before sorting……22
33
11
cc
bb
aa
Printing List after sorting……
11
22
33
aa
bb
cc