import java.util.*;
public class demo1
{
public static void main(String[] args)
{
HashSet<String> hash_set = new HashSet<String>();
hash_set.add("C#");
hash_set.add("C++");
hash_set.add("Java");
hash_set.add("Python");
hash_set.add("Perl");
hash_set.add("Ruby");
System.out.println("Original Hash Set: " + hash_set);
String[] new_array = new String[hash_set.size()];
hash_set.toArray(new_array);
System.out.println("Array elements: ");
for(String element : new_array)
{
System.out.println(element);
}
}
}
Java
Program to convert a hash set to an array.

Written by
View ProfileNikhil Juneja
Passionate software developer and technical contributor at TutorialsLink.
