Concatenate the String values of all Maps in a List

二次信任 提交于 2019-12-05 16:24:59

Try this :

list.stream().map(Map::values).flatMap(Collection::stream).collect(Collectors.joining(","))

The flatMap method flattens out a Collection<Stream<String>> into a single Stream<String>.

Alternately, you can try what @Holger suggested in the comments.

Note that since you are using a Map, there is no guarantee that the order will be preserved. You might see the output as 45678,12345 at your end. If you wish to preserve the order, you can use a LinkedHashMap instead of a HashMap.

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