java lambda expressions use

Find java

1. Find the set

userList.stream().filter(e->e.getId().equals(userCard.getUserId())).findFirst().get().getPhone();

Careful users may find the above code has a bug collection to find it will complain when found.

Modifications to see the second one.

2. Find a collection of objects that match. And take the first phone assigned to the new object 

userList.stream().filter(e->e.getId().equals(userCard.getUserId())).findFirst().ifPresent (a->{
                newInfo.setPhone(a.getPhone());
            });

3. Take a field set list

 List<Integer> integerList =projectList.stream().map(e -> e.getId()).collect(Collectors.toList());

 

Published 123 original articles · won praise 47 · views 120 000 +

Guess you like

Origin blog.csdn.net/u010919083/article/details/103679976