user5447339
user5447339

Reputation:

set a boolean variable basis on multiple key check on a map

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:

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

Answers (1)

NickL
NickL

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

Related Questions