1.

How To Sort Arraylist In Java?

Answer»

Collections class has a STATIC method sort which can be used for SORTING an arraylist.

There are TWO overloaded versions of sort method -

  • public static <T extends Comparable<? super T>> void sort(List<T> list) - Sorts the specified list into ascending order, according to the NATURAL ordering of its elements.
  • public static <T> void sort(List<T> list, Comparator<? super T> c) - Sorts the specified list according to the order induced by the specified comparator.

If you have a List called cityList it can be sorted LIKE this - 

Collections.sort(cityList);

Collections class has a static method sort which can be used for sorting an arraylist.

There are two overloaded versions of sort method -

If you have a List called cityList it can be sorted like this - 

Collections.sort(cityList);



Discussion

No Comment Found