import java.util.Set;
import java.util.HashSet;
public class SetToArray {
public static void main(String[] args) {
// creating our set
// set internally uses hashmap
Set<String> set = new HashSet<>();
// adding element to our set
set.add("Gunjan");
set.add("Rehana");
set.add("Kiara");
set.add("Kayra");
set.add("Varsha");
set.add("Sayra");
set.add("Rehana");
// creating an array of object type
Object[] arr = set.toArray();
// getting size of set and array
System.out.println("Size of set is = " + set.size());
System.out.println("Length of Array = " + arr.length);
// printing array using for each loop
System.out.println("Printing Array using for each loop :");
for (Object o : arr) {
System.out.print(o + " ");
}
System.out.println();
System.out.println("Printing Array using for loop :");
// priting array using for loop
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}