I have a map with collegeID and Student Id
I am checking if the Map has both the keys and values associated with them
This is always giving false
This is my code
Map<String, String> allDataMap = new HashMap<>();
allDataMap.put("college_id", "1095");
allDataMap.put("student_id", "108");
boolean present = allDataMap.entrySet().stream()
.filter(map -> map.getKey().equals("college_id") && map.getValue().equals("1095"))
.filter(map -> map.getKey().equals("student_id") && map.getValue().equals("108"))
.findAny().isPresent() ? true : false;
System.out.println(present);
filterdoes?allDataMap.getOrDefault("college_id","").equals("1095") && allDataMap.getOrDefault("student_id","").equals("108"). However, this feels like it's based on a design problem, i.e. you seem to be looking for a certain student - why do you represent students as maps?boolean present = ....isPresent()?true:false- you're converting a boolean into a boolean - why? Just useboolean present = .... isPresent()(when appropriate in the first place).