Iterating List of List in java8 [duplicate]

微笑、不失礼 提交于 2020-08-20 05:00:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!