List bean集合去除重复lambda 表达式 应用 stream() 方式去重复,交集,并集
package ****,***,***; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import xxx.test.A; import xxx.test.B;
/**
* 陈金玉
**/ public class Test { public static void main(String[] args) { List <A> aL=new ArrayList<A>(); A a=new A(); a.setAaa("aaa"); a.setReq("reqaaa"); a.setRes("resaaa"); aL.add(a); A a1=new A(); a1.setAaa("aaa1"); a1.setReq("reqaaa1"); a1.setRes("reqaaa1"); aL.add(a1); List <B> bL=new ArrayList<B>(); B b=new B(); b.setFff("aaa"); b.setGgg("f1"); b.setRes("f2"); bL.add(b); List<B> toList = bL.parallelStream().map( user ->{ A user1 = aL.stream().filter(u ->!user.getFff().equals(u.getAaa())).findFirst().orElse(null); if(null != user1){ user.setFff(user1.getAaa()); user.setGgg(user1.getReq()); user.setRes(user1.getRes()); } return user; }).collect(Collectors.toList()); for( B ttt:toList ) { System.out.println(ttt.getGgg()); System.out.println(ttt.getRes()); System.out.println(ttt.getFff()); System.out.println("--------------"); } } }