List of usage examples for java.util TreeSet TreeSet
public TreeSet()
From source file:Main.java
public static void main(String[] args) { // create set SortedSet<String> set = new TreeSet<String>(); // populate the set set.add("from"); set.add("java2s.com"); set.add("tutorial"); set.add("java"); // create a synchronized sorted set SortedSet<String> sorset = Collections.synchronizedSortedSet(set); System.out.println("Sorted set is :" + sorset); }
From source file:Main.java
public static void main(String[] args) { String[] cities = { "A", "B", "C", "D", "E", "F" }; NavigableSet<String> citiesSet = new TreeSet<String>(); for (String city : cities) citiesSet.add(city);//from w w w. jav a 2s. c o m System.out.println(citiesSet.ceiling("A")); }
From source file:Main.java
public static void main(String[] args) { NavigableSet<Integer> ns = new TreeSet<>(); ns.add(0);/* w w w. j a v a2s . c o m*/ ns.add(1); ns.add(2); ns.add(3); ns.add(4); ns.add(5); ns.add(6); // Get a reverse view of the navigable set NavigableSet<Integer> reverseNs = ns.descendingSet(); // Print the normal and reverse views System.out.println("Normal order: " + ns); System.out.println("Reverse order: " + reverseNs); NavigableSet<Integer> threeOrMore = ns.tailSet(3, true); System.out.println("3 or more: " + threeOrMore); System.out.println("lower(3): " + ns.lower(3)); System.out.println("floor(3): " + ns.floor(3)); System.out.println("higher(3): " + ns.higher(3)); System.out.println("ceiling(3): " + ns.ceiling(3)); System.out.println("pollFirst(): " + ns.pollFirst()); System.out.println("Navigable Set: " + ns); System.out.println("pollLast(): " + ns.pollLast()); System.out.println("Navigable Set: " + ns); System.out.println("pollFirst(): " + ns.pollFirst()); System.out.println("Navigable Set: " + ns); System.out.println("pollFirst(): " + ns.pollFirst()); System.out.println("Navigable Set: " + ns); System.out.println("pollFirst(): " + ns.pollFirst()); System.out.println("Navigable Set: " + ns); System.out.println("pollFirst(): " + ns.pollFirst()); System.out.println("pollLast(): " + ns.pollLast()); }
From source file:Main.java
public static void main(String[] args) { String[] cities = { "A", "B", "C", "D", "E", "F" }; NavigableSet<String> citiesSet = new TreeSet<String>(); for (String city : cities) citiesSet.add(city);//from ww w .ja v a2s .c om System.out.println(citiesSet.floor("A")); }
From source file:Main.java
public static void main(String[] argv) { // Create the sorted set Set<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(); System.out.println(element); }//w w w . j a v a2 s . c o m // Create an array containing the elements in a set String[] array = (String[]) set.toArray(new String[set.size()]); Arrays.toString(array); }
From source file:MainClass.java
public static void main(String[] args) { String[] coins = { "Penny", "nickel", "dime", "Quarter", "dollar" }; Set set = new TreeSet(); for (int i = 0; i < coins.length; i++) set.add(coins[i]);// w ww . j a v a2 s . c om System.out.println(Collections.min(set)); System.out.println(Collections.min(set, String.CASE_INSENSITIVE_ORDER)); System.out.println(""); System.out.println(Collections.max(set)); System.out.println(Collections.max(set, String.CASE_INSENSITIVE_ORDER)); }
From source file:CityNavigator.java
public static void main(String[] args) { String[] cities = { "A", "B", "C", "D", "E", "F" }; citiesSet = new TreeSet<String>(); for (String city : cities) citiesSet.add(city);//from w w w . j av a2s .c om }
From source file:CityNavigator.java
public static void main(String[] args) { String[] cities = { "A", "B", "C", "D", "E", "F" }; citiesSet = new TreeSet<String>(); for (String city : cities) citiesSet.add(city);/* w w w . j a v a2s . c o m*/ System.out.println(citiesSet.floor("A")); }
From source file:CityNavigator.java
public static void main(String[] args) { String[] cities = { "A", "B", "C", "D", "E", "F" }; citiesSet = new TreeSet<String>(); for (String city : cities) citiesSet.add(city);/*www.j a v a 2 s . co m*/ System.out.println(citiesSet.higher("A")); }
From source file:CityNavigator.java
public static void main(String[] args) { String[] cities = { "A", "B", "C", "D", "E", "F" }; citiesSet = new TreeSet<String>(); for (String city : cities) citiesSet.add(city);/*from ww w.j a va2 s .co m*/ System.out.println(citiesSet.lower("A")); }