I am new to Java. I have a HashSet of String and I am trying to convert the contains into a String[]. I follow the solution here Converting from HashSet<String> to String[] But still got error. Here is my code:
Set set = new HashSet<String>();
// Add elements into set
// ...
String[] words = set.toArray(new String[set.size()]);
The error I got is "incompatible types: java.lang.Object[] cannot be converted to java.lang.String[]"
Set<String>e.g.,Set<String> set = new HashSet<>();