Ordered list in Java
Collections.sort() in Java with Examplesjava.util.Collections.sort() method is present in java.util.Collections class. It is used to sort the elements present in the specified list of Collection in ascending order. Example: Let us suppose that our list contains {"Geeks For Geeks", "Friends", "Dear", "Is", "Superb"} After using Collection.sort(), we obtain a sorted list as {"Dear", "Friends", "Geeks For Geeks", "Is", "Superb"}Sorting an ArrayList in ascending order
Output: List after the use of Collection.sort() : [Dear, Friends, Geeks For Geeks, Is, Superb]
Output:
Output : Unsorted 111 bbbb london 131 aaaa nyc 121 cccc jaipur Sorted by rollno 111 bbbb london 121 cccc jaipur 131 aaaa nycArrays.sort() vs Collections.sort() We can use Collections.sort() to sort an array after creating a ArrayList of given array items.
Output: List after the use of Collection.sort() : [Code, Geeks, Practice, Quiz]This article is contributed by Mohit Gupta. Article is wished to be useful to the esteemed Geeks.
Article Tags :
Java
Java - util package Java-Collections Java-Collections-Class Java-Functions Practice Tags :
Java Java-Collections
Read Full Article
|