Reputation:
I have a map in which these three keys will be present:
Map<String, String> holder = new HashMap<>();
holder.put("abc", "qwer");
holder.put("pqr", "dsds");
holder.put("def", "jghghg");
// data for some other keys
Here is what I need to do:
abc
and pqr
both are not present and only def
key is present then I want to assign true to a boolean variable other I will set as false.So I did something like this but it doesn't work. Looks like my logic is wrong somehow.
boolean flag = !(holder.containsKey("abc") || holder.containsKey("pqr"));
Upvotes: 0
Views: 109
Reputation: 4276
Literal translation from what you wanted it to do. NOT-contains 'abc' AND NOT-contains 'pqr' AND contains 'def'
!holder.containsKey("abc") && !holder.containsKey("pqr") && holder.containsKey("def")
Upvotes: 3