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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:24:21+00:00 2026-05-30T15:24:21+00:00

Possible Duplicate: Java – HashMap vs Map objects What’s the difference between : Map

  • 0

Possible Duplicate:
Java – HashMap vs Map objects

What’s the difference between :

Map <String,Integer>myMap = new HashMap<String,Integer>();

VS

HashMap <String,Integer> map = new HashMap<String,Integer>();  

Regards,Ron

  • 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-30T15:24:24+00:00Added an answer on May 30, 2026 at 3:24 pm

    There is no difference between the objects. There is a difference in the interface you have to the object. In the first case, the interface is HashMap<String, Object>, whereas in the second it’s Map<String, Object>. The underlying object, though, is the same.

    The advantage to using Map<String, Object> is that you can change the underlying object to be a different kind of map without breaking your contract with any code that’s using it. If you declare it as HashMap<String, Object>, you have to change your contract if you want to change the underlying implementation…


    Also Map is the static type of map, while HashMap is the dynamic type of map. This means that the compiler will treat your map object as being one of type Map, even though at runtime, it may point to any subtype of it…

    This practice of programming against interfaces instead of implementations has the added benefit of remaining flexible: You can for instance replace the dynamic type of map at runtime, as long as it is a subtype of Map (e.g. LinkedHashMap), and change the map’s behavior on the fly.

    A good rule of thumb is to remain as abstract as possible on the API level: If for instance a method you are programming must work on maps, then it’s sufficient to declare a parameter as Map instead of the stricter (because less abstract) HashMap type. That way, the consumer of your API can be flexible about what kind of Map implementation they want to pass to your method..

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

Sidebar

Related Questions

Possible Duplicate: Java Ordered Map I have list of product object in the HashMap<Integer,Product>
Possible Duplicate: Java: What is the difference between implementing Comparable and Comparator? Difference between
Possible Duplicate: Java Strings: “String s = new String(”silly“);” I was going through some
Possible Duplicate: java String concatenation StringBuilder vs String concatenation in toString() in Java I
Possible Duplicate: java String concatenation How to Improve performance of this chunk of code
Possible Duplicate: Java Generics To be more specific, whats the role of the <String>
Possible Duplicate: Java Integer Division, How do you produce a double? double wang =
Possible Duplicate: Java string comparison? I have encounter the following problem, I have an
Possible Duplicate: Java: convert List<String> to a join()d string Having this: List<String> elementNames =
Possible Duplicate: Java - escape string to prevent SQL injection Hi. I constantly am

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.