The ArrayList class does not have any method to sort the objects stored in it.So we have can use java.util.Collections.sort(aList); where aList is an ArrayList instance. But the question arises as to how the sorting is being done by the sort method of Collections class in Java. If one looks at the code of sort method of Collections class in Java API then we can see the following code: 1 2 3 4 5 6 7 8 9 public static void sort(List list) { Object a[] = list.toArray(); Arrays.sort(a); ListIterator i = list.listIterator(); for ( int j= 0 ; j< a.length; j++) { i.next(); i.set(a[j]); } } The sort method of Arrays class is being called so we see the code for sort method in the Arrays class: ?
About Java and it's related concepts..