You could try this one too, if you are unsure, how much of the cities could come in the filter condition in near future..
public void filterStudents(Map<Integer, Student> studentsMap){
final List<String> includedCities = List.of("DELHI", "NEW YORK", "AMSTERDEM", "SOME MORE");
Map<Integer, Student> filteredStudentsMap =
studentsMap.entrySet()
.stream()
.filter(s -> includedCities.contains(s.toUpperCase()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
UPDATE (after comments by @JoachimSauer):
This should be much finer..
public void filterStudents(Map<Integer, Student> studentsMap){
final List<String> includedCities = List.of("DELHI", "NEW YORK", "AMSTERDEM", "SOME MORE");
Map<Integer, Student> filteredStudentsMap =
studentsMap.entrySet()
.stream()
.filter(s -> exclusiveCities.stream().anyMatch(s::equalsIgnoreCase))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
UPDATE (after comments by @Holger):
Even Better..
public void filterStudents(Map<Integer, Student> studentsMap){
final Set<String> includedCities = new TreeSet<>(CASE_INSENSITIVE_ORDER);
Collections.addAll( includedCities , "DELHI", "NEW YORK", "AMSTERDEM", "SOME MORE");
Map<Integer, Student> filteredStudentsMap =
studentsMap.entrySet()
.stream()
.filter(includedCities::contains))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}