Stream사용하면서 몇개 쓸만한거
1. 값이 포함되어있으면 boolean으로 돌려주기
public static List<Number> staticList = Arrays.asList(1,2,3,4,5,6,7,8,9,10);
public static void main(String[] args) {
List<Number> mine = Arrays.asList(2,4,6);
System.out.println(isValid(mine));
}
public static boolean isValid(List<Number> lists) {
return staticList.stream()
.anyMatch(lists::contains);
}
2. 교차되는 내용 다시 리스트로 돌려주기
public class Main {
public static List<Number> staticList = Arrays.asList(1,2,3,4,5,6,7,8,9,10);
public static void main(String[] args) {
List<Number> mine = Arrays.asList(2,4,6);
System.out.println(intersect(mine));
}
public static List<Number> intersect(List<Number> lists) {
return staticList.stream()
.filter(lists::contains)
.collect(Collectors.toList());
}
}