List of usage examples for java.util NavigableSet lower
E lower(E e);
From source file:is.java
public static void main(String[] args) { List<Integer> list = Arrays.asList(3, 2, 4, 1, 5); NavigableSet<Integer> ns = new TreeSet<Integer>(list); System.out.println("Ascending order (default): " + ns); Iterator<Integer> descendingIterator = ns.descendingIterator(); StringBuilder sb = new StringBuilder("Descending order: "); while (descendingIterator.hasNext()) { int m = descendingIterator.next(); sb.append(m + " "); }/*from w w w . j ava 2s. c om*/ System.out.println(sb); int greatest = ns.lower(3); System.out.println("Lower of 3 = " + greatest); int smallest = ns.higher(3); System.out.println("Higher of 3 = " + smallest); }
From source file:NavigableSetDemo.java
public static void main(String[] args) { List<Integer> list = Arrays.asList(3, 2, 4, 1, 5); NavigableSet<Integer> ns = new TreeSet<Integer>(list); System.out.println("Ascending order (default): " + ns); Iterator<Integer> descendingIterator = ns.descendingIterator(); StringBuilder sb = new StringBuilder("Descending order: "); while (descendingIterator.hasNext()) { int m = descendingIterator.next(); sb.append(m + " "); }//from w w w . j av a 2 s .co m System.out.println(sb); int greatest = ns.lower(3); System.out.println("Lower of 3 = " + greatest); int smallest = ns.higher(3); System.out.println("Higher of 3 = " + smallest); }
From source file:Main.java
public static void main(String[] args) { NavigableSet<Integer> ns = new TreeSet<>(); ns.add(0);/*ww w . j a v a 2s. 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:com.google.gwt.emultest.java.util.TreeSetTest.java
public void testLower() { NavigableSet<E> set = createNavigableSet(); set.add(getKeys()[0]);/*from w ww . j a v a 2 s . c o m*/ assertEquals(null, set.lower(getLessThanMinimumKey())); assertEquals(null, set.lower(getKeys()[0])); assertEquals(getKeys()[0], set.lower(getKeys()[1])); assertEquals(getKeys()[0], set.lower(getGreaterThanMaximumKey())); assertEquals(set.toArray()[0], set.lower(getKeys()[1])); set.add(getKeys()[1]); assertEquals(null, set.lower(getLessThanMinimumKey())); assertEquals(null, set.lower(getKeys()[0])); assertEquals(getKeys()[0], set.lower(getKeys()[1])); assertEquals(getKeys()[1], set.lower(getGreaterThanMaximumKey())); }