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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:07:32+00:00 2026-05-26T13:07:32+00:00

All, I am working on an existing system where the developer had defined a

  • 0

All,

I am working on an existing system where the developer had defined a lot of HashMaps with following definition:

HashMap<String, Comparable> x = new HashMap<String, Comparable>();

Now, there is absolutely no need of comparison for the value part of the hashmap since it simply represents only a single piece of information. The developer used Comparable since the only expected values were String and int types(converted to Integer object) and the developer assumed the best way to store both data types is using Comparable interface.

So, I went ahead and changed the code since there was no point of comparison here by defining the HashMap as:

HashMap<String, Object> y = new HashMap<String, Object>();

I had timed the code execution for before and after change. I am a bit surprised as to why the code is taking more time to execute after my changes were deployed (though not a performance bottleneck currently).

Can anyone please help me understand the change in behavior due to my code updates?

  • 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-26T13:07:32+00:00Added an answer on May 26, 2026 at 1:07 pm

    Both are identical in terms of performance as the value is not used for hashing (only the key is).

    How are you timing your code? Make sure you time each test case separately. Do not do the following as the second test will have the benefit of the first test having “warmed-up” the JVM. My guess is that your test is flawed or you’re seeing normal execution time variations.

    public static void main(String[] args) {
        for loop {
            test HashMap<String, Comparable>
        }
    
        for loop {
            test HashMap<String, Object>
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm regularly facing the following situation; I am working on an existing system built
On a project I'm working on, there is an existing messaging system that sends
I'm working on a existing embedded system (memory is limited, Flash is limited, ...)
They were all working fine on my XAMMP sandbox but now nothing. Something im
We have three developers and one tester all working against the same database. We
My wordpress*(a custom template)* nav is all working on all of the pages but
I'm working through the NerdDinner ASP.NET MVC 1.0 example. I have it all working
I have 2 div boxes. It's all working fine but when the browser is
I have configured the wildcard DNS of *.mydomain.com and it's all working properly. My
I'm trying to write a 2d array into an output file, it's all working

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.