问题
I was wondering, How can we iterate a multilevel list using stream API in Java 8
For example,
List<List<String>> multiList = new ArrayList<>();
List<String> names= Arrays.asList("a","b");
List<String> fewMoreNames= Arrays.asList("e","f");
multiList.add(names);
multiList.add(fewMoreNames);
As per Java 8, I should go something like below
multiList.stream().... ?
I wanted to do this fluently(using internal iteration).Any explanation would be appreciated.
回答1:
Got it folks, it was easy one. I was not looking at the API closely. One of the solution is
multiList .stream().forEach((x) -> x.stream().forEach(System.out::println));
来源:https://stackoverflow.com/questions/28342441/iterating-list-of-list-in-java8