listAll.stream().map(entity -> new Resp(entity)).collect(Collectors.toList());
.stream() 将listAll转成流,然后map中每一个entity都做一个操作,如:都转成Resp类,然后再打包成list
如果接收的话,List<Resp> list=listAll.stream().map(entity -> new Resp(entity)).collect(Collectors.toList());
这样list中的数据都是转过的,但是原先的listAll的数据并不会改变。
lambda表达式我的理解是 ()->{} 括号中的是参数,{}中的是方法,
比如 numbers.stream().map(e->e+1).collect(Collectors.toList()).forEach(n->System.out.print(n));
前一个:参数e 方法是:e+1
后一个是:参数n 方法是:System.out.print(n)
暂时我只用到了这个