[ACCEPTED]-Converting from HashSet<String> to String[]-hashset
Accepted answer
set.toArray(new String[set.size()]);
0
Answer of JB Nizet is correct, but in case 3 you did this to transform to a CSV like 2 string, with Java 8 you can now do:
Set<String> mySet = new HashSet<>(Arrays.asList("a", "b", "c"));
System.out.println(String.join(", ", mySet));
Output is: a, b, c
This 1 allows to bypass array notation (the []
).
The JB Nizet's answer is correct. In Java 15, the 1 better answer is:
set.toArray(new String[0]);
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.