Click here to watch in Youtube :
https://www.youtube.com/watch?v=6AXX8TF3SeE&list=UUhwKlOVR041tngjerWxVccw
CollectionsSortExample.java
Output
https://www.youtube.com/watch?v=6AXX8TF3SeE&list=UUhwKlOVR041tngjerWxVccw
CollectionsSortExample.java
import java.util.ArrayList; import java.util.Collections; public class CollectionsSortExample { public static void main(String[] args) { ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("Dog"); arrayList.add("Ball"); arrayList.add("Cat"); arrayList.add("Apple"); 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 : [Dog, Ball, Cat, Apple] After Sorting : [Apple, Ball, Cat, Dog]
https://sites.google.com/site/javaee4321/java-collections/CollectionsSortDemoSortStringApp.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment