Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:58:51+00:00 2026-06-05T01:58:51+00:00

Ok, here is the bit I do not understand. If you attempt to retrieve

  • 0

Ok, here is the bit I do not understand.
If you attempt to retrieve an object using the get() method and null is returned, it is still possible that null may be stored as the object associated with the key you supplied to the get() method. You can determine if this is the case by passing your key of the object to containsKey() method for map. This returns true if key is stored in the map
So, how is containsKey() supposed to tell me if the value associated with the key supplied is null?
This is the reference if you wanna check. Page 553

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:58:52+00:00Added an answer on June 5, 2026 at 1:58 am

    Consider this simple snippet of code:

    Map<String, String> m = new HashMap<String, String>();
    m.put("key1", "value1");
    m.put("key2", null);
    
    System.out.println("m.get(\"key1\")=" + m.get("key1"));
    System.out.println("m.containsKey(\"key1\")=" + m.containsKey("key1"));
    
    System.out.println("m.get(\"key2\")=" + m.get("key2"));
    System.out.println("m.containsKey(\"key2\")=" + m.containsKey("key2"));
    
    System.out.println("m.get(\"key3\")=" + m.get("key3"));
    System.out.println("m.containsKey(\"key3\")=" + m.containsKey("key3"));
    

    As you can see I put in the map two values, one of which is null. Thene i asked the map for three values: two of them are present (one is null), one is not. Look at the result:

    m.get("key1")=value1
    m.containsKey("key1")=true
    m.get("key2")=null
    m.containsKey("key2")=true
    m.get("key3")=null
    m.containsKey("key3")=false
    

    The second and the third are the tricky part. key2 is present with null value so, using get() you cannot discriminate whether the element is not in the map or is in the map with a null value. But, using containsKey() you can, as it returns a boolean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The link to the content can be seen here: http://bit.ly/K6jRGI The issue is that
Here's a bit of an abstract question. Would it be appropriate to say that
Bit confused here, I have an on-demand instance but do I get charged even
I'm having a bit of a weird issue here, basically, im using hibernate together
Struggling a bit here... My view controller adheres to following protocols In my init
I'm panicking a bit here... In the project navigator, I clicked and renamed my
OK, I confess at the outset I'm over my head a bit here. I've
Here's a bit of a newbie Python question about instance variables. Consider the following
Ok guys im a bit stuck here. I usually use jquery to do this
Right guys, here's a bit of a discussion -- I'm creating a website with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.