Click here to watch in Youtube :
https://www.youtube.com/watch?v=EvttSJNropE&list=UUhwKlOVR041tngjerWxVccw
TreeSetExample.java
Output
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); } }
sortedSet : [10, 20, 30, 40, 50] treeSet : [10, 20, 30, 40, 50]
https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoConsAcceptsSortedSet.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment