Add values to TreeSet : TreeSet « Collections Data Structure « Java






Add values to TreeSet

    

import java.util.TreeSet;

class TreeSetDemo {
  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("D");

    System.out.println(ts);
  }
}

   
    
    
  








Related examples in the same category

1.TreeSet, SortedSet and HashSet
2.Get Synchronized Set from Java TreeSet example
3.Check if a particular value exists in Java TreeSet example
4.Copy all elements of Java TreeSet to an Object Array Example
5.Get Head Set from Java TreeSet example
6.Get lowest and highest value stored in Java TreeSet
7.Get Size of Java TreeSet
8.Get Sub Set from Java TreeSet
9.Get Tail Set from Java TreeSet
10.Iterate through elements of Java TreeSet
11.Remove all elements from Java TreeSet
12.Remove specified element from Java TreeSet
13.Sort items in a Set
14.Loop and remove element from a TreeSet
15.Creating a Sorted Set
16.Comparable with a sorted collection.
17.A TreeSet that ensures it never grows beyond a max size.