I have the following hashmap out of which I want to find if it contains a specific key out of the below 4 keys. In Java 7 I can do below. How can I do the same in Java8?
Map<String, String> filterParamsMap = new HashMap<>();
filterParamsMap.put("CRN", "1234");
String key;
for (String customReference : filterParamsMap.keySet()) {
if (customReference.equalsIgnoreCase("CCN") || customReference.equalsIgnoreCase("PRN")
|| customReference.equalsIgnoreCase("PCCN") || customReference.equalsIgnoreCase("CRN")) {
key = customReference;
}
I tried but I'm able to check just 1 string out of the above 4. Also, it returns boolean whereas my output should be a String.
String key = filterParamsMap.keySet().stream().anyMatch(r->r.contains("CRN"));
I cannot do the below:
String key = filterParamsMap.keySet().stream().anyMatch(r->r.contains("CRN")||r->r.contains("PRN")||r->r.contains("PCCN")
||r->r.contains("CCN"));