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<Integer> treeadd = new TreeSet<Integer>();

    treeadd.add(1);
    treeadd.add(3);/*from  w  w w.ja v a2s .  co m*/
    treeadd.add(17);
    treeadd.add(2);

    System.out.println("Remove 17: " + treeadd.remove(17));
}

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.subSet("2", "5");

    System.out.println("SortedSet 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"));

    Iterator itr = tSet.iterator();

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }//from  www  .jav  a2  s. c om
}

From source file:Main.java

public static void main(String[] args) {

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

    treeadd.add(12);
    treeadd.add(11);/*from  w w  w  . j  a va 2 s.com*/
    treeadd.add(16);
    treeadd.add(15);

    // getting the higher value for 13
    System.out.println("Higher value of 13: " + treeadd.higher(13));
}

From source file:Main.java

public static void main(String[] args) {

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

    treeadd.add(12);
    treeadd.add(11);// w  w w  . j  a v a  2  s  .  c  o  m
    treeadd.add(16);
    treeadd.add(15);

    // getting the first lowset element
    System.out.println("First lowest element: " + treeadd.first());
}

From source file:Main.java

public static void main(String[] args) {

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

    treeadd.add(12);
    treeadd.add(11);//from w  ww.  j  av  a 2 s . c o  m
    treeadd.add(16);
    treeadd.add(15);

    // getting the floor value for 13
    System.out.println("Floor value for 13: " + treeadd.floor(13));
}

From source file:Main.java

public static void main(String[] args) {

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

    treeadd.add(12);
    treeadd.add(11);// www  .  j a  v a  2s . c o  m
    treeadd.add(16);
    treeadd.add(15);

    // getting ceiling value for 13
    System.out.println("Ceiling value for 13: " + treeadd.ceiling(13));
}

From source file:Main.java

public static void main(String[] args) {

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

    treeadd.add(1);
    treeadd.add(3);//from  w w  w. ja v a2  s  . c o  m
    treeadd.add(17);
    treeadd.add(2);
    treeadd.add(20);

    // displaying the greatest element < 17
    System.out.println("Greatest element less than 17 is: " + treeadd.lower(17));
}

From source file:Main.java

public static void main(String[] args) {

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

    treeadd.add(12);
    treeadd.add(13);//from   ww  w . j av  a  2 s.c om
    treeadd.add(14);
    treeadd.add(15);

    // check existence of 15  
    System.out.println("Checking existence of 15 ");
    System.out.println("Is 15 there in the set: " + treeadd.contains(15));
}

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 . j a v  a  2 s .com*/
    treeadd.add(17);
    treeadd.add(22);

    Iterator<Integer> iterator = treeadd.iterator();

    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
}