Copy all elements of Java TreeSet to an Object Array Example : TreeSet « Collections Data Structure « Java






Copy all elements of Java TreeSet to an Object Array Example

   
       
import java.util.TreeSet;

public class Main {
  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);
    }
  }
}

   
    
    
  








Related examples in the same category

1.Add values to TreeSet
2.TreeSet, SortedSet and HashSet
3.Get Synchronized Set from Java TreeSet example
4.Check if a particular value exists in Java TreeSet 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.