List of usage examples for java.util TreeSet TreeSet
public TreeSet()
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeone = new TreeSet<Integer>(); TreeSet<Integer> treetwo = new TreeSet<Integer>(); treeone.add(12);// w ww. ja v a 2s.co m treeone.add(13); treeone.add(14); treetwo.add(15); treetwo.add(16); treetwo.add(17); // adding treetwo to treeone treeone.addAll(treetwo); Iterator<Integer> iterator = treeone.iterator(); while (iterator.hasNext()) { System.out.print(iterator.next()); } }
From source file:Main.java
public static void main(String args[]) { Set<String> hset = new TreeSet<String>(); // populate the set hset.add("from"); hset.add("java2s.com"); hset.add("tutorial"); // get typesafe view of the set Set<String> tsset = Collections.checkedSet(hset, String.class); System.out.println(tsset);/*w w w. j a v a 2s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { SortedSet<String> names = new TreeSet<>(); names.add("HTML"); names.add("Java"); names.add("SQL"); names.add("CSS"); System.out.println("Sorted Set: " + names); System.out.println("First: " + names.first()); System.out.println("Last: " + names.last()); SortedSet<String> ssBeforeCSS = names.headSet("CSS"); System.out.println(ssBeforeCSS); SortedSet<String> ssBetwenCSSAndHTML = names.subSet("CSS", "HTML"); System.out.println(ssBetwenCSSAndHTML); SortedSet<String> ssBetwenCSSAndHTML2 = names.subSet("CSS", "HTML"); System.out.println(ssBetwenCSSAndHTML2); SortedSet<String> ssCSSAndAfter = names.tailSet("CSS"); System.out.println(ssCSSAndAfter); }
From source file:Main.java
public static void main(String args[]) { SortedSet<String> set = new TreeSet<String>(); PriorityQueue<String> p = new PriorityQueue<String>(set); System.out.println(p);/*from w w w. ja v a 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { Set<Counter> set = new TreeSet<Counter>(); set.add(new Counter("A", 1)); set.add(new Counter("B", 5)); set.add(new Counter("C", 10)); set.add(new Counter("D", 4)); set.add(new Counter("E", 3)); set.add(new Counter("F", 5)); set.add(new Counter("G", 15)); set.add(new Counter("H", 225)); set.add(new Counter("I", 225)); for (Counter f : set) { System.out.println(f);/*from w w w . jav a2 s . c om*/ } }
From source file:Main.java
public static void main(String[] args) { Set<Item> s = new TreeSet<Item>(); s.add(new Item("item1", 5)); s.add(new Item("item2", 1)); s.add(new Item("item3", 7)); s.add(new Item("item4", 1)); for (Item it : s) { System.out.println("Item is:" + it.getName() + " with value:" + it.getValue()); }//from w w w . j ava2 s .c om }
From source file:Main.java
public static void main(String args[]) { SortedSet<String> sset = new TreeSet<String>(); sset.add("tutorial"); sset.add("from"); sset.add("java2s.com"); // get typesafe view of the sorted set SortedSet<String> tsset = Collections.checkedSortedSet(sset, String.class); System.out.println(tsset);// w w w . java 2s .c o m }
From source file:Main.java
public static void main(String[] argv) throws Exception { SortedSet<String> set = new TreeSet<String>(); set.add("b"); set.add("c"); set.add("a"); Iterator it = set.iterator(); while (it.hasNext()) { Object element = it.next(); }/*w w w. j a v a 2 s . c o m*/ String[] array = (String[]) set.toArray(new String[set.size()]); }
From source file:Main.java
public static void main(String[] args) { // Create a sorted set of some names SortedSet<String> sortedNames = new TreeSet<>(); sortedNames.add("Java"); sortedNames.add("SQL"); sortedNames.add("HTML"); sortedNames.add("CSS"); // Print the sorted set of names System.out.println(sortedNames); }
From source file:Main.java
public static void main(String[] s) { SortedSet<String> set = new TreeSet<String>(); set.add("Welcome"); set.add("to"); set.add("java2s.com"); System.out.println("Initial set value: " + set); // create unmodifiable sorted set Set<String> unmodsortset = Collections.unmodifiableSortedSet(set); // try to modify the sorted set unmodsortset.add("Hello"); }