Linkedhashset to array in java

We can use toArray() method to convert linkedhashset to array in java.

Syntax:

linkedHashSet.toArray(strArray);

Example:

package com.w3spoint;
 
import java.util.LinkedHashSet;
 
public class Test {
  public static void main(String args[]){
	//Create LinkedHashSet
	LinkedHashSet<String> linkedHashSet = new LinkedHashSet<String>();
        //Add elements to LinkedHashSet
	linkedHashSet.add("Jai");
	linkedHashSet.add("Mahesh");
	linkedHashSet.add("Vikas");
	linkedHashSet.add("Sahil");
	linkedHashSet.add("Sachin");
	linkedHashSet.add("Vijay");
	System.out.println("LinkedHashSet: " + linkedHashSet);
	String[] strArray = new String[linkedHashSet.size()];
	linkedHashSet.toArray(strArray);
        System.out.println("Array content:");
        for(String string:strArray){
            System.out.println(string);
        }
  }
}

Output

LinkedHashSet: [Jai, Mahesh, Vikas, Sahil, Sachin, Vijay]
Array content:
Jai
Mahesh
Vikas
Sahil
Sachin
Vijay
Please follow and like us:
Content Protection by DMCA.com
togel situs toto situs togel situs toto situs toto agen togel situs togel situs togel togel situs togel resmi situs togel situs togel situs toto link togel togel online