Copy all elements of TreeSet to an Object Array - Java Collection Framework

Java examples for Collection Framework:TreeSet

Description

Copy all elements of TreeSet to an Object Array

Demo Code


import java.util.TreeSet;
 
public class Main {
 
  public static void main(String[] args) {
    TreeSet tSet = new TreeSet();
    tSet.add(new Integer("1"));
    tSet.add(new Integer("2"));
    tSet.add(new Integer("3"));
    Object[] objArray = tSet.toArray();
   //from w w w  .  ja  v a  2s  .co m
    for(int index=0; index < objArray.length ; index++)
      System.out.println(objArray[index]);
  }
}

Result


Related Tutorials