I think it's easier to understand what i mean showing my code
String[] words = text.split(" ");
List<char[]> wordsInChars = new ArrayList<char[]>();
for(String i: words){
wordsInChars.add(i.toCharArray());
}
so I create an array of Strings, taking the text variable as input, then i want to pass it to the List without going through that loop. Is it possible to skip the for loop altogether?
I've tried
List<char[]> wordsInChars = Arrays.asList(Arrays.stream(words).forEach(w -> w.toCharArray()));
Either way, which approach should be used? The code with the for loop works, but am not sure if just doing it all at declaration is just better.
edit: I actually managed with
List<char[]> wordsInChars = Arrays.stream(words).map(w -> w.toCharArray()).collect(Collectors.toList());
But feedback on which one of the two is better practice, is welcomed.