In this section we discuss method Array Collections.sort(ArrayList) for item arrayList.
See Example:
import java.util.ArrayList;
import java.util.Collections;
public class Details {
public static void main(String args[]) {
ArrayList<String> arrlist = getArrayList();
}
public static ArrayList<String> getArrayList(){
// first Array
ArrayList<String> firstArr = new ArrayList<String>();
firstArr.add("Item8");
firstArr.add("Item3");
firstArr.add("Item5");
firstArr.add("Item6");
System.out.println(" ---before sort array----");
for(String arr : firstArr){
System.out.println(arr);
}
System.out.println("---After Sort--- ");
Collections.sort(firstArr);
for(String arr : firstArr){
System.out.println(arr);
}
return firstArr;
}
}
//result:
---before sort array----
Item8
Item3
Item5
Item6
---After Sort---
Item3
Item5
Item6
Item8
EmoticonEmoticon