Example usage for java.util TreeSet TreeSet

List of usage examples for java.util TreeSet TreeSet

Introduction

In this page you can find the example usage for java.util TreeSet TreeSet.

Prototype

public TreeSet(SortedSet<E> s) 

Source Link

Document

Constructs a new tree set containing the same elements and using the same ordering as the specified sorted set.

Usage

From source file:Main.java

public static void main(String[] args) {
    TreeSet<Integer> tree = new TreeSet<Integer>(Collections.reverseOrder());

    tree.add(12);/*w w w.  j  a  v  a 2 s . co m*/
    tree.add(13);
    tree.add(14);
    tree.add(15);
    tree.add(16);
    tree.add(17);

    // using comparator
    System.out.println(tree.comparator());

}

From source file:Main.java

public static void main(String args[]) throws Exception {
    String elements[] = { "A", "C", "D", "G", "F" };
    TreeSet<String> set = new TreeSet<String>(Arrays.asList(elements));
    System.out.println(set);//from w  ww. ja v a2 s  .  co m
    System.out.println(set.first());
    System.out.println(set.last());
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    String elements[] = { "A", "C", "D", "G", "F" };
    TreeSet set = new TreeSet(Arrays.asList(elements));

    System.out.println(set.headSet("D"));
    System.out.println(set.tailSet(""));
}

From source file:Main.java

public static void main(String args[]) throws Exception {

    String elements[] = { "A", "C", "D", "G", "F" };
    TreeSet<String> set = new TreeSet<String>(Arrays.asList(elements));

    System.out.println(set.subSet("C", "F"));
}

From source file:Comp.java

public static void main(String args[]) throws Exception {
    String elements[] = { "Irish Setter", "Poodle", "English Setter", "Gordon Setter", "Pug" };
    Set set = new TreeSet(Collections.reverseOrder());
    for (int i = 0, n = elements.length; i < n; i++) {
        set.add(elements[i]);/*from   www . j a  v  a 2s .  com*/
    }
    System.out.println(set);
    System.out.println(((TreeSet) set).comparator());
}

From source file:Main.java

public static void main(String args[]) throws Exception {

    String elements[] = { "A", "C", "D", "G", "F" };
    TreeSet<String> set = new TreeSet<String>(Arrays.asList(elements));

    System.out.println(set.headSet("D"));
    System.out.println(set.tailSet(""));
}

From source file:Main.java

public static void main(String args[]) throws Exception {

    String elements[] = { "java2s.com", "C", "D", "G", "F" };
    TreeSet<String> set = new TreeSet<String>(Arrays.asList(elements));
    TreeSet<String> set1 = new TreeSet<String>(set);
    System.out.println(set1);// ww  w.jav  a 2 s  .  c o  m
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    String elements[] = { "A", "C", "D", "G", "F" };
    TreeSet set = new TreeSet(Arrays.asList(elements));

    System.out.println(set.tailSet("C"));
    System.out.println(set.headSet("C"));
    System.out.println(set.headSet("C\0"));
    System.out.println(set.tailSet("C\0"));
    System.out.println(set.subSet("C", "F\0"));
    System.out.println(set.subSet("C", "C\0"));
    System.out.println(set.subSet("C", "C"));
}

From source file:Main.java

public static void main(String args[]) throws Exception {

    String elements[] = { "java2s.com", "C", "D", "G", "F" };
    TreeSet<String> set = new TreeSet<String>(Arrays.asList(elements));

    System.out.println(set.headSet("D"));
    System.out.println(set.tailSet(""));
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    String elements[] = { "A", "C", "D", "G", "F" };
    Set set = new TreeSet(Arrays.asList(elements));

    System.out.println(set);//from www .  j  a v  a  2 s . co  m
}