Assume we have a List<String>
with some values containing the delimiter ,
, how do we convert split and merge into a List<String>
without the delimiter ,
?
Input: [ "1,2", "3,4", "5" ]
Output: [ "1", "2", "3", "4", "5" ]
Imperative code
List<String> input = Arrays.asList("1,2", "3,4", "5");
List<String> output = new ArrayList<>();
for (String str : input) {
for (String split : str.split(",")) {
output.add(split);
}
}