4

怎么用Lambda进行list合并以及去重

 2 years ago
source link: https://www.oschina.net/question/3447476_2324404
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

怎么用Lambda进行list合并以及去重

Jessica丶 发布于 前天 17:01
阅读 322


List<String> list = new ArrayList<String>();
list.add("a,b");
list.add("a,c");
list.add("c,d");

上面的list集合里面的,放在一起,用逗号切割,然后去重,返回{"a","b","c","d"}这个集合,用Lambda怎么实现

sprouting

前天 21:03
List<String> list = new ArrayList<>();
list.add("a,b");
list.add("a,c");
list.add("c,d");

List<String> collect1 = list.stream().map(obj -> Arrays.asList(obj.split(","))).flatMap(Collection::stream).distinct().collect(Collectors.toList());
System.out.println(collect1);

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK