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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:34:26+00:00 2026-05-19T10:34:26+00:00

Since, the hardware is becoming very cheap and has very huge memory available these

  • 0

Since, the hardware is becoming very cheap and has very huge memory available these days.Why cannot we use generically a common DataStructure like HashMap for all the scenarios ? If not, is there a short guideline somewhere to know which DataStructure to use in which scenario?.

  • 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-19T10:34:27+00:00Added an answer on May 19, 2026 at 10:34 am

    (Edit: This answer assumes that you’re asking within the context of storing key -> value mappings. If your data doesn’t naturally represent mappings, for example a list of Strings, then any kind of Map is a poor way to represent it, both in terms of performance and in terms of confusing anyone else who looks at your code.)

    Generally speaking, you can. If you’re using a map with immutable keys that have decent hashCode() implementations (e.g. String, any of the auto-boxed primitives), then a HashMap will be perfectly acceptable in general.

    However, the different data structures exist for a reason – they all offer difference performance (and occasionally correctness) semantics, so in certain situations you may wish to pick others.

    For example, if you want your map entries to be visited in a particular order during iteration (based on the keys), you can use a TreeMap. If you want the iteration order to be based on the order they were inserted, use a LinkedHashMap. If you want good performance under simple concurrent access (with put-if-absent semantics), use a ConcurrentHashMap. If your keys are enums, then an EnumMap is hands-down the most efficient implementation. If you want the keys to be stored as weak refs, use a WeakHashMap. If you want to perform lookups based on the exact object being used (making it safe for mutable keys), use IdentityHashMap.

    Not to mention that if you know (but are unable to change) that your keys have a poorly-implemented hashCode() method, especially if it’s inconsistent with equals, then HashMap may be a poor choice anyway.

    And there are many other possible features you may wish your data structure to have that aren’t covered able, included (but not limited to):

    • Specific iteration order that isn’t key-sorted or insertion-order
    • Size-boundedness (especially with customisable choice of which entry to kick out)
    • Soft/Phantom references for keys
    • Lazy initialisation when a get() is performed for a key that isn’t there

    And so on. This is especially likely if your own domain objects have certain properties that a specific Map implementation could take advantage of for faster/cleaner/enhanced performance (which, of course, a generic library implementation could never do).


    Addressing the “hardware is cheap” statement – this is true, but programmer time and user time is not. In some cases, the application’s critical loop may involve a lot of map lookups, such that speeding up these lookups will have a noticeable effect on performance. Of course, this usually won’t be the case, but if it is, choosing a better performing map for the specific situation (a simple example that comes to mind is using an EnumMap where appropriate) will yield performance gains – which can be very important.

    Alternatively, some map implementations simply make the surrounding code easier to write, easier to understand, and less likely to harbour bugs. An example here might be a case of a lazy-initialising map (something like Google Collections’ ComputingMap). While you can write some code with lazy-init semantics around a standard HashMap, by packing all of this logic inside the map implementation itself it becomes easier to test for correctness – and the client logic is much simpler.

    So cheap hardware/space doesn’t mean that HashMaps are optimal for everything. In fact, if anything it’s a counterargument – HashMaps are reasonably space-efficient compared to the more bespoke alternatives you might adopt. With lots of cheap space available, it’s entirely possible to trade off space against time, storing lots of information in order to speed up lookups.


    Note that I’ve interpreted your question as “why might you sometimes use other classes of Map?” rather than “which other Maps should you use and when?” If it’s the latter, feel free to rephrase or ask another question that focuses on this more specifically.

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

Sidebar

Related Questions

since Android 3.0 the android.hardware.SensorManager.getRotationMatrix method result has to be remaped to work as
Since Android canvas is not hardware accelerated (untill 3), I want to use OpenGL
Since REST is stateless, each request that comes in has no knowledge of the
Since now I have only used plugin for editing and the way I use
Since input and raw_input() stop the program from running anymore, I want to use
Since each thread has its own stack, its private data can be put on
I am writing some hardware specific code, where I want to use C Macros,
I'm building a dashboard'ish application for a special purpose hardware that has physical buttons
I'm having problem at mipmapping the textures on different hardware. I use the following
We're currently writing an application for which IT has already purchased hardware for. Their

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.