Monday 29 June 2015

Java : Collection Framework : Collections (Sort LinkedList)


Click here to watch in Youtube : 
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);

    }

}
Output
Before Sorting  : [Dog, Ball, Cat, Apple]

After Sorting   : [Apple, Ball, Cat, Dog]
To Download CollectionsSortDemoLinkedListApp Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/CollectionsSortDemoLinkedListApp.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment