Is there any built-in method in Java which allows us to convert comma separated String to some container (e.g array, List or Vector)? Or do I need to write custom code for t
There are many ways to solve this using streams in Java 8 but IMO the following one liners are straight forward:
String commaSeparated = "item1 , item2 , item3";
List result1 = Arrays.stream(commaSeparated.split(" , "))
.collect(Collectors.toList());
List result2 = Stream.of(commaSeparated.split(" , "))
.collect(Collectors.toList());