Click here to watch in Youtube : https://www.youtube.com/watch?v=EvttSJNropE&list=UUhwKlOVR041tngjerWxVccwTreeSetExample.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]