List of usage examples for java.util SortedSet add
boolean add(E e);
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"); System.out.println(set.last()); }
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"); System.out.println(set.first()); }
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"); System.out.println(set.comparator()); }
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(); }//from w w w.j a v a 2 s. c om 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 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 ww .j av a 2 s . c o m }
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"); }
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) { // 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) { // Sort the names based on their length, placing null first SortedSet<String> names = new TreeSet<>(Comparator.nullsFirst(Comparator.comparing(String::length))); names.add("XML"); names.add("CSS"); names.add("HTML"); names.add(null); // Adds a null // Print the names names.forEach(System.out::println); }