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(12);/*from ww w. j a va2 s. c o m*/ treeadd.add(11); treeadd.add(16); treeadd.add(15); // getting the higher value for 13 System.out.println("Higher value of 13: " + treeadd.higher(13)); }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(12);/* w ww . ja v a 2 s.com*/ treeadd.add(11); treeadd.add(16); treeadd.add(15); // getting the first lowset element System.out.println("First lowest element: " + treeadd.first()); }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(12);/*from w w w .j a va 2 s .c om*/ treeadd.add(11); treeadd.add(16); treeadd.add(15); // getting the floor value for 13 System.out.println("Floor value for 13: " + treeadd.floor(13)); }
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 av a 2s.c o m treeadd.add(3); treeadd.add(17); treeadd.add(2); treeadd.add(20); // displaying the greatest element < 17 System.out.println("Greatest element less than 17 is: " + treeadd.lower(17)); }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> tSet = new TreeSet<Integer>(); System.out.println("Size of TreeSet : " + tSet.size()); tSet.add(new Integer("1")); tSet.add(new Integer("2")); tSet.add(new Integer("3")); System.out.println(tSet.size()); // remove one element from TreeSet using remove method tSet.remove(new Integer("1")); System.out.println("Size of TreeSet after removal : " + tSet.size()); }
From source file:Main.java
public static void main(String[] args) { TreeSet<String> ss = new TreeSet<String>(); String[] fruits = { "apples", "pears", "grapes", "bananas", "kiwis" }; for (String fruit : fruits) { ss.add(fruit);/*from w w w . j a va 2s. com*/ } for (String s : ss) { System.out.print(s); } }
From source file:Main.java
public static void main(String[] args) { Set<String> set = new TreeSet<String>(); set.add("Z"); set.add("A"); set.add("F"); set.add("B"); set.add("H"); set.add("X"); set.add("N"); for (String item : set) { System.out.print(item + " "); }//w w w . j a v a 2 s .co m }
From source file:Main.java
public static void main(String[] args) { TreeSet<String> tSet = new TreeSet<String>(); tSet.add("1"); tSet.add("2"); tSet.add("3"); tSet.add("4"); tSet.add("5"); SortedSet sortedSet = tSet.headSet("3"); System.out.println("Head Set Contains : " + sortedSet); }
From source file:Main.java
public static void main(String[] args) { TreeSet<String> tSet = new TreeSet<String>(); tSet.add("1"); tSet.add("2"); tSet.add("3"); tSet.add("5"); tSet.add("4"); SortedSet sortedSet = tSet.tailSet("2"); System.out.println("Tail Set Contains : " + sortedSet); }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> tSet = new TreeSet<Integer>(); tSet.add(new Integer("1")); tSet.add(new Integer("2")); tSet.add(new Integer("3")); Iterator itr = tSet.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); }/* w w w . ja va 2s. c o m*/ }