import java.util.Iterator;
import java.util.TreeSet;
import java.util.Set;
import javax.management.monitor.StringMonitor;
public class TreeSetToArray {
public static void main(String[] args) {
// creating our TreeSet
Set<String> ts = new TreeSet<>();
// adding element to our set
// insertion order is maintained here
ts.add("Neha");
ts.add("Nisha");
ts.add("Nishu");
ts.add("Rekha");
ts.add("Madhu");
ts.add("Disha");
ts.add("Tara");
ts.add("Tara"); // duplicate element can't be added
Object[] ar_copy = new Object[ts.size()];
ar_copy = ts.toArray();
for (Object o : ar_copy) {
System.out.print(o + ",");
}
System.out.println();
}
}