Can I rewrite this code using Stream Api, what will it look like?
Set<ContactGroup> groups = user.getGroups(); Set<String> groupNames = new HashSet<>(); for (ContactGroup group : groups) { groupNames.add(group.getName()); }
Can I rewrite this code using Stream Api, what will it look like?
Set<ContactGroup> groups = user.getGroups(); Set<String> groupNames = new HashSet<>(); for (ContactGroup group : groups) { groupNames.add(group.getName()); }
Source: https://ru.stackoverflow.com/questions/957557/
All Articles
groups.stream().map(g->g.getName()).collect(Collectors.toSet())
- Grundy