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

  • Home
  • SEARCH
  • 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 949593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:25:36+00:00 2026-05-15T23:25:36+00:00

I have a hashmap that is 101 keys in size, but I know for

  • 0

I have a hashmap that is 101 keys in size, but I know for sure about 6 of those have no data inside, and there may be more without data as well. What exactly is inside the empty indexes? Is it null? or is there a Hash(index).isEmpty() method that I can use to see if its empty?

I realize there is a isEmpty method inside hashmap, but I thought that only checked if the entire map was empty not just a single index.

  • 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-05-15T23:25:36+00:00Added an answer on May 15, 2026 at 11:25 pm

    Well, for the keys to arrive there with no data, you have to put them there.

    If you did map.put(key, null) then yes the data for that key is null. You always have to give the second parameter to the method, you can’t just map.put(key).

    If you know for sure that a certain key should have no data you could try going into debug mode and putting a watch for myMap.get(myEmptyKey) and see what you get (in case that no data is an empty object or something else, you should be able to see that).

    Edit: Some code would be useful to help you, but if I understand correctly you do something like this:

    for (Object obj : list) {
        if (matchesCriteriaX(obj)) {
             map.put("X", obj);
        else if (matchesCriteriaY(obj)) {
             map.put("Y", obj);
        }
    }
    

    Well, if you do that and try to do map.get("X"), but you never actually put anything for that key (becaus no object matched criteria X), you will most definitely get back a null.

    On the other hand, if you did something like

    Map<String, List<Object>> map = new HashMap<String, List<Object>>();
    map.add("X", new ArrayList<Object>());
    map.add("Y", new ArrayList<Object>());
    for (Object obj : list) {
        if (matchesCriteriaX(obj)) {
             List<Object> list = map.get("X");
             list.add(obj);
        else if (matchesCriteriaY(obj)) {
             List<Object> list = map.get("Y");
             list.add(obj);
        }
    }
    

    then you could check if a category is empty by doing map.get("x").isEmpty() since List has that method (and it would be empty if no object matched the key criteria).

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

Sidebar

Related Questions

I have a HashMap (hshFields) of HashMaps (ecd_date, owned_by, etc..) with keys (label, size,
I have a Java HashMap whose keys are instances of java.lang.Object, that is: the
I'm building a hashmap class that can have string keys and ints, bools, strings
I have a HashMap that I am serializing and deserializing to an Oracle db,
I have a HashMap relating Keys to Strings, and I need to compare some
I have a Hashmap that, for speed reasons, I would like to not require
I have a HashMap that I'm using in Processing and I'd like to increment
If I have a HashMap that looks like this: HashMap<String, MyObject> where the String
I have a HashMap object that I am getting on a JSP page. HashMap<Integer,Gift_product>
I have hashmap and its keys are like folder/1.txt,folder/2.txt,folder/3.txt and value has these text

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.