TreeSet elements adding
In this chapter you will learn:
Add elements to a TreeSet
boolean add(E e)
Adds the specified element to this set if it is not already present.boolean addAll(Collection<? extends E> c)
Adds all of the elements in the specified collection to this set.
import java.util.TreeSet;
//j a va 2 s . c o m
public class Main {
public static void main(String args[]) {
TreeSet<String> ts = new TreeSet<String>();
ts.add("C");
ts.add("A");
ts.add("B");
ts.add("E");
ts.add("F");
ts.add("java2s.com");
System.out.println(ts);
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Collections