1

I have a hashmap when i am printing this hashmap the output is like this

{KEY_CH_UP=KEY_CH_UP, KEY_PANEL_CH_UP=KEY_PANEL_CH_UP, KEY_7=KEY_7, KEY_6=KEY_6, KEY_5=null}

Now i want to get all the keys which is having

values == null ;
3
  • 5
    and what have you tried to get what you want? Read whathaveyoutried.com Commented Jan 9, 2013 at 11:07
  • @GauravSakhardande: I agree, great blog. But I'm not the author ;) Commented Jan 9, 2013 at 11:10
  • I do not see how Java EE is relevant here. HashMap is a part of standard Java SE. Retaging. Commented Jan 9, 2013 at 11:23

1 Answer 1

4

Iterate over the like below and check if the value is null :

Map<String, String> map = new HashMap<String, String>();
        for(Map.Entry<String, String> en: map.entrySet()){
            if(en.getValue()==null){
                System.out.println(en.getKey());
            }
        }
Sign up to request clarification or add additional context in comments.

1 Comment

+1 Basically the OP is searching a Map by value. It doesn't have a more efficient way of doing this than iterating over every value which is why searching by value could indicate a poor design choice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.