Advanced Java Tutorial

Total available pages count: 55
Subject - Java Technologies

Sorting in Collection

Using Sorting, we can sort element of -


  • String 
  • User-defined class
  • Wrapper class


The Collections in java provide the static method for sorting elements of it if an element is in Set type, you can use TreeSet but it can’t sort the element in provides a method for sorting elements in List type.

public void sort(List list)
/**Sort the elements of List.
*List elements must be of the comparable type. */


The String classes & wrapper classes are used to implement a comparable interface if we store objects of string or wrapper class, it can be comparable.