Java TreeSet.add(E e)
Syntax
TreeSet.add(E e) has the following syntax.
public boolean add(E e)
Example
In the following code shows how to use TreeSet.add(E e) method.
/*from w w w . j a va 2s. c o m*/
import java.util.Iterator;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) {
TreeSet <Integer> treeadd = new TreeSet<Integer> ();
treeadd.add(12);
treeadd.add(13);
treeadd.add(14);
treeadd.add(15);
Iterator<Integer> iterator = treeadd.iterator();
while (iterator.hasNext()){
System.out.print(iterator.next());
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »