Click here to watch in Youtube :
https://www.youtube.com/watch?v=FskYdxsOK7M&list=UUhwKlOVR041tngjerWxVccw
CollectionsSortExample.java
Output
https://www.youtube.com/watch?v=FskYdxsOK7M&list=UUhwKlOVR041tngjerWxVccw
CollectionsSortExample.java
import java.util.ArrayList; import java.util.Collections; /* * Example of sort(List<T> list) method */ public class CollectionsSortExample { public static void main(String[] args) { ArrayList<Double> arrayList = new ArrayList<Double>(); arrayList.add(1.4); arrayList.add(1.2); arrayList.add(1.3); arrayList.add(1.1); System.out.println("Before Sorting : " + arrayList + "\n"); /* * Sorts the specified list into ascending order, according to the * natural ordering of its elements. * * All elements in the list must implement the Comparable interface. */ Collections.sort(arrayList); System.out.println("After Sorting : " + arrayList); } }
Before Sorting : [1.4, 1.2, 1.3, 1.1] After Sorting : [1.1, 1.2, 1.3, 1.4]
https://sites.google.com/site/javaee4321/java-collections/CollectionsSortDemoSortDoubleApp.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment