Copy all elements of LinkedHashSet to an Object Array

 

import java.util.Arrays;
import java.util.LinkedHashSet;

public class Main {
  public static void main(String[] args) {

    LinkedHashSet linkedHashSet = new LinkedHashSet();

    linkedHashSet.add("1");
    linkedHashSet.add("2");
    linkedHashSet.add("java2s.com");

    Object[] objArray = linkedHashSet.toArray();
    System.out.println(Arrays.toString(objArray));
  }
}

 

The output:


[1, 2, java2s.com]
Home 
  Java Book 
    Collection  

LinkedHashSet:
  1. LinkedHashSet class
  2. Check if an element exists in LinkedHashSet using contains method
  3. Copy all elements of LinkedHashSet to an Object Array