Convert Set into array : HashSet « Collections Data Structure « Java






Convert Set into array

     
 
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
  public static void main(String[] args) {
    Set<Object> set = new HashSet<Object>();
    set.add("A");
    set.add(new Long(10));
    set.add(new Date());

    List<Object> list = new ArrayList<Object>(set);
    Object[] objects = list.toArray();

    for (int i = 0; i < objects.length; i++) {
      Object object = objects[i];
      System.out.println("Object = " + object);
    }
  }
}
 

   
    
    
    
    
  








Related examples in the same category

1.Add values to HashSet
2.HashSet implementation of setHashSet implementation of set
3.Generic collection conversion: HashSet and ArrayList
4.Remove one set from another set
5.Remove element from HashSet
6.Find maximum element of Java HashSet
7.Find Minimum element of Java HashSet
8.Get Enumeration over Java HashSet
9.Get Synchronized Set from Java HashSet
10.Check if a particular element exists in Java HashSet
11.Copy all elements of Java HashSet to an Object Array
12.Get Size of Java HashSet
13.Iterate through elements of Java HashSet
14.Integer value set
15.Listing the Elements of a Collection(iterate over the elements of set or list)
16.Remove specified element from Java HashSet
17.Remove all elements from Java HashSet
18.Convert array to Set
19.Implements a HashSet where the objects given are stored in weak references
20.Convert an ArrayList to HashSet
21.Create an array containing the elements in a set
22.Duplicate elements are discarded
23.A memory-efficient hash set.
24.Compact HashSet
25.Coarse-grained hash set.
26.Concurrent hash set that allows the lock array to be resized.
27.A CompactHashSet implements the set interface more tightly in memory and more efficiently than Java's java.util.HashSet.
28.Concurrent HashSet