Click here to watch in Youtube :
https://www.youtube.com/watch?v=dUJLsfDQ5nM&list=UUhwKlOVR041tngjerWxVccw
CollectionsSortExample.java
Output
https://www.youtube.com/watch?v=dUJLsfDQ5nM&list=UUhwKlOVR041tngjerWxVccw
CollectionsSortExample.java
import java.util.Collections; import java.util.LinkedList; /* * Example of sort(List<T> list) method. */ public class CollectionsSortExample { public static void main(String[] args) { LinkedList<String> linkedList = new LinkedList<String>(); linkedList.add("Dog"); linkedList.add("Ball"); linkedList.add("Cat"); linkedList.add("Apple"); System.out.println("Before Sorting : " + linkedList + "\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(linkedList); System.out.println("After Sorting : " + linkedList); } }
Before Sorting : [Dog, Ball, Cat, Apple] After Sorting : [Apple, Ball, Cat, Dog]
https://sites.google.com/site/javaee4321/java-collections/CollectionsSortDemoLinkedListApp.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment