Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<ClassName> filteredObjects = objects.stream()
- .collect(Collectors.groupingBy(ClassName::getSecNumber))
- .values().stream()
- .flatMap(os -> os.stream().anyMatch(o -> o.getType() == Type.NEW) ?
- os.stream().filter(o -> o.getType() != Type.LEGACY) :
- os.stream()
- ).collect(Collectors.toList());
- Collection<T> result = list.stream()
- .collect(toMap(T::getSecNumber,
- Function.identity(),
- (l, r) -> l.getType() == Type.LEGACY ? r : l))
- .values();
- List<T> result =
- list.stream()
- .collect(groupingBy(T::getSecNumber))
- .values()
- .stream()
- .flatMap(l -> l.stream().anyMatch(e -> e.getType() == Type.NEW) ?
- l.stream().filter(e -> e.getType() != Type.LEGACY) :
- l.stream())
- .collect(toList());
Add Comment
Please, Sign In to add comment