Here is the situation: We have a Student object which contains courseId as one of its fields. I want to return true if there is any student with course in history.
List<Student> students = new ArrayList();
students.stream.anyMap(s -> getFromDataBase(s.getCourseId()).name == "History");
Now, there is an optimization to prevent DB calls. Since many students can have the same courseId, it makes sense to filter out redundant courseId.
Eg:
List<Student> students = new ArrayList();
Set<Id> course = new HashSet<>();
for (Student s : students) {
course.add(s.getCourseId());
}
course.stream.anyMap(s -> getFromDataBase(s.getCourseId()).name == "History");
Now is there some way in Java-8, which I can use so that I don't need to do the following stuff:
Set<Id> course = new HashSet<>();
for (Student s : students) {
course.add(s.getCourseId());
}
courseId in (courseId1, courseId2, …)