Wednesday, 14 January 2015

Java : Collection Framework : TreeSet (Constructor Accepts SortedSet)


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=EvttSJNropE&list=UUhwKlOVR041tngjerWxVccw

TreeSetExample.java
import java.util.SortedSet;
import java.util.TreeSet;

/*
 * Example of TreeSet(SortedSet<E> s) Constructor.
 */
public class TreeSetExample
{
    public static void main( String[] args )
    {

        SortedSet<Integer> sortedSet = new TreeSet<Integer>();

        sortedSet.add(40);
        sortedSet.add(20);
        sortedSet.add(30);
        sortedSet.add(10);
        sortedSet.add(50);

        System.out.println("sortedSet : " + sortedSet);

        /*
         * Constructs a new tree set containing the same elements and using the
         * same ordering as the specified sorted set.
         */
        TreeSet<Integer> treeSet = new TreeSet<Integer>(sortedSet);

        System.out.println("\ntreeSet : " + treeSet);

    }
}
Output
sortedSet : [10, 20, 30, 40, 50]

treeSet : [10, 20, 30, 40, 50]
To Download TreeSetDemoConsAcceptsSortedSet Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoConsAcceptsSortedSet.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment