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 6189739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:27:56+00:00 2026-05-24T02:27:56+00:00

Why do I get different results when I run equivalent code for hashtable and

  • 0

Why do I get different results when I run equivalent code for hashtable and hashmaps?

Iterator<Integer> it = ht.keySet().iterator();
while(it.hasNext()) {
    i = it.next();
    System.out.println(i + " : " + ht.get(i));
}

ht is a hashtable object. If i replace with hm, a hashmap object, it doesn’t print the values from get() method instead prints null. Why is that?

  • 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-24T02:27:57+00:00Added an answer on May 24, 2026 at 2:27 am

    While not technically an “answer” to your question (which is not possible due to insufficient code provided in the question), I do have this suggestion regarding code style.

    This would have helped you avoid the bug you found in your code (according to your later comment).

    The code you provided:

    Iterator<Integer> it = ht.keySet().iterator();
    while(it.hasNext()) {
        i = it.next();
        System.out.println(i + " : " + ht.get(i));
    }
    

    is equivalent to this more elegant foreach loop over the entry set:

    for (Map.Entry<Integer, Object> entry : ht.entrySet()) {
        System.out.println(entry.getKey() + " : " + entry.getValue());
    }
    

    Use this form in preference to using the iterator directly if you can.
    It’s neater, and less code == good

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

Sidebar

Related Questions

Can someone explain why I get different results from these two statements? I thought
I need to return two different results in a single query. When I run
I'm wondering whether I will ever get a different result when producing a checksum
We are trying to get different SharePoint web applications to authenticate against different sub-domains.
Two Questions: Will I get different sequences of numbers for every seed I put
Here is an example to get different parts of a filename bash-3.2$ pathandfile=/tmp/ff.txt bash-3.2$
I must get two different client application talk without any kind of broker or
Can someone please let me know how to get the different segments of the
I would like to get data from from different webpages such as addresses of
Can you get the distinct combination of 2 different fields in a database table?

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.