实现的效果就是 把姓和名拼接一下 然后以逗号分隔 返回一个字符串
Data
@AllArgsConstructor
@NoArgsConstructor
public static class us{
private String firsName;
private String lastName;
}
public static void main(String[] args) {
List<us> objects = new ArrayList<>();
objects.add(new us("李","闯闯"));
objects.add(new us("李","世民"));
objects.add( new us("李","自成") );
System.out.println( "处理前:"+objects );
String collect1 = objects.stream().map( (us u) -> {
u.setFirsName( u.firsName + u.lastName);
return u;
} ).map( us -> us.getFirsName() ).collect( Collectors.joining( "," ) );
System.out.println("处理后:"+collect1 );
}
输出结构
处理前:[PaymentServiceImpl.us(firsName=李, lastName=闯闯), PaymentServiceImpl.us(firsName=李, lastName=世民), PaymentServiceImpl.us(firsName=李, lastName=自成)]
处理后:李闯闯,李世民,李自成