List tmp= new DATA().findEntities();
List tmp1 = new DATA().findEntities().stream().filter(
IN (tmp) ???
).collect(Collectors.toList());
How to simulate a tipical IN clause (like in mysql or JPA) using a Predicate ?
解决方案
I decided to update my comment to an answer. The lambda expression for your requested Predicate (where Y should be a concrete type) looks as following:
element -> tmp.contains(element)
Because the collection's contains method has the same signature as the predicate's test method, you can use a method reference (here an instance method reference):
tmp::contains
A full example:
List tmp = Arrays.asList(1, 2, 3);
List tmp1 = Arrays
.stream(new Integer[] { 1, 2, 3, 4, 5 })
.filter(tmp::contains)
.collect(Collectors.toList());
System.out.println(tmp1);
This prints
[1, 2, 3]