Newsletter |
How to sort ArrayList in java, Sorting java Collections
Core Java » on Oct 23, 2012 { 4 Comments } By Sivateja
Let us see how to sort values in java collections, List/ArrayList. We can achieve this by using Collections class, Collections class contains a method sort(Collection Object), just give your collection object to the sort() method that’s it, consider this example….
SortCollection.java
package java4s; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public class SortCollection { public static void main(String... args) { List li = new ArrayList(); li.add("India"); li.add("United States"); li.add("Malaysia"); li.add("Australia"); li.add("Lundon"); Collections.sort(li); for(String temp: li) { System.out.println("Countries : "+temp); } } }
Output
Countries : Australia
Countries : India
Countries : Lundon
Countries : Malaysia
Countries : United States
You Might Also Like
::. About the Author .:: | ||
Comments
4 Responses to “How to sort ArrayList in java, Sorting java Collections”
Can You Please Update the Jasper Reporting Tool
can we please write the code to display arraylist elements in dropdown
ex
if click on country it disply the state dropdown
superb sir
My Question is—— if we remove element from Arraylist index basis.how to find which element is removed from arraylist.mean find removed element
plz sir……………..