Example usage for java.util TreeSet add

List of usage examples for java.util TreeSet add

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Adds the specified element to this set if it is not already present.

Usage

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("4");
    tSet.add("5");

    boolean blnExists = tSet.contains("3");
    System.out.println("3 exists in TreeSet ? : " + blnExists);
}

From source file:TreeSetDemo.java

public static void main(String args[]) {
    TreeSet<String> ts = new TreeSet<String>();

    ts.add("C");
    ts.add("A");/*from  w  ww . ja  v a 2s.  c o m*/
    ts.add("B");
    ts.add("E");
    ts.add("F");
    ts.add("D");

    System.out.println(ts);
}

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"));

    Object[] objArray = tSet.toArray();
    for (Object obj : objArray) {
        System.out.println(obj);/*from w  w  w.j  a  v a  2s  .c  om*/
    }
}

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"));

    System.out.println(tSet);/*ww w.  j a  v  a 2 s .c  o  m*/
    System.out.println("Was 2 removed from TreeSet ? " + tSet.remove(new Integer("2")));
    System.out.println(tSet);
}

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");

    System.out.println("Lowest value Stored in Java TreeSet is : " + tSet.first());
    System.out.println("Highest value Stored in Java TreeSet is : " + tSet.last());
}

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"));

    System.out.println("TreeSet before removal : " + tSet);
    tSet.clear();//w ww. j a v  a  2s.  co  m
    System.out.println("TreeSet after removal : " + tSet);
    System.out.println("Is TreeSet empty ? " + tSet.isEmpty());
}

From source file:Main.java

public static void main(String[] args) {

    TreeSet<Integer> treeadd = new TreeSet<Integer>();

    treeadd.add(1);
    treeadd.add(13);/*  w ww.ja  va 2 s. c o m*/
    treeadd.add(17);
    treeadd.add(2);

    System.out.println("Last highest element: " + treeadd.last());
}

From source file:Main.java

public static void main(String[] args) {

    TreeSet<Integer> treeadd = new TreeSet<Integer>();

    treeadd.add(1);
    treeadd.add(13);//from w w w  .j a v  a 2 s .c o m
    treeadd.add(17);
    treeadd.add(2);

    System.out.println("Size of the tree set is: " + treeadd.size());
}