List of usage examples for java.util TreeSet TreeSet
public TreeSet()
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);/*from www .ja v a2s . c om*/ treeadd.add(13); treeadd.add(17); treeadd.add(2); // create descending iterator Iterator<Integer> iterator = treeadd.descendingIterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);//from w w w.j a va 2s .co m treeadd.add(3); treeadd.add(17); treeadd.add(2); System.out.println("Last element is: " + treeadd.pollLast()); Iterator<Integer> iterator = treeadd.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);//w w w .ja v a 2 s. co m treeadd.add(3); treeadd.add(17); treeadd.add(2); System.out.println("First element is: " + treeadd.pollFirst()); Iterator<Integer> iterator = treeadd.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> tree = new TreeSet<Integer>(); tree.add(12);/* ww w . j a va 2s .c om*/ tree.add(13); tree.add(14); tree.add(15); tree.add(16); tree.add(17); // getting values less than 15 TreeSet<Integer> treeheadset = (TreeSet) tree.headSet(15); Iterator<Integer> iterator = treeheadset.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(12);//from ww w . j a v a2 s. co m treeadd.add(13); treeadd.add(14); treeadd.add(15); Iterator<Integer> iterator = treeadd.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } treeadd.clear(); System.out.println(treeadd.size()); }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);/*from ww w . j a v a 2s. c om*/ treeadd.add(2); treeadd.add(3); treeadd.add(4); treeadd.add(5); treeadd.add(6); treeadd.add(7); treeadd.add(8); TreeSet<Integer> treetailsetincl = (TreeSet<Integer>) treeadd.tailSet(5, true); Iterator<Integer> iterator = treetailsetincl.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);//from ww w . jav a 2s.co m treeadd.add(13); treeadd.add(17); treeadd.add(2); // creating reverse set TreeSet<Integer> treereverse = (TreeSet<Integer>) treeadd.descendingSet(); // create descending set Iterator<Integer> iterator = treereverse.iterator(); //Tree set data in reverse order while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);// w ww . j av a 2 s . c o m treeadd.add(2); treeadd.add(3); treeadd.add(4); treeadd.add(5); treeadd.add(6); treeadd.add(7); treeadd.add(8); TreeSet<Integer> treesubset = (TreeSet<Integer>) treeadd.subSet(3, 7); Iterator<Integer> iterator = treesubset.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);/* w w w.j av a 2s.c o m*/ treeadd.add(2); treeadd.add(3); treeadd.add(4); treeadd.add(5); treeadd.add(6); treeadd.add(7); treeadd.add(8); TreeSet<Integer> treetailset = (TreeSet<Integer>) treeadd.tailSet(4); Iterator<Integer> iterator = treetailset.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);//from w ww .ja v a 2s . c om treeadd.add(2); treeadd.add(3); treeadd.add(4); treeadd.add(5); treeadd.add(6); treeadd.add(7); treeadd.add(8); TreeSet<Integer> treesubset = (TreeSet<Integer>) treeadd.subSet(3, true, 7, true); Iterator<Integer> iterator = treesubset.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }