Stream. -Match Method
- allMatch() : 모든 요소들이 매개 값(Predicate)로 주어진 조건을 만족하는지 조사
- anyMatch() : 최소한 한 개의 요소가 주어진 조건에 만족하는 지 조사
- noneMatch() : 모든 요소들이 주어진 조건을 만족하지 않는지 조사
1. 중복 되는 값 찾기.
List<Entity> list = 값;
List<Entity> vaildList = 값;
List<Entity> noneEntityList = list.stream().filter(l -> vaildList.stream().anyMatch(n -> {
return l.Id().equals(n.Id());
})).collect(Collectors.toList());
2. 중복 되지 않는 값 찾기
List<Entity> list = 값;
List<Entity> vaildList = 값;
List<Entity> noneEntityList = list.stream().filter(l -> vaildList.stream().noneMatch(n -> {
return l.Id().equals(n.Id());
})).collect(Collectors.toList());
3. 다중 조건(필드)으로 찾기
List<Entity> list = 값;
List<Entity> vaildList = 값;
List<Entity> noneEntityList = list.stream().filter(l -> vaildList.stream().anyMatch(n -> {
return l.Id().equals(n.Id()) && l.getName().equals(n.getName());
})).collect(Collectors.toList());