-3

I have many records in to fetch and it could be in millions, I want to use hashmap, but I am not sure if that is ok or what would be the memory implications.

Please suggest

Thanks VIvek

blpvivek
  • 11
  • 2
  • What are the class types of the keys and values you want to store in your map? – Bohemian Jan 21 '14 at 01:54
  • 2
    It is very unlikely you're going to have enough memory to store millions of anything in memory regardless of data structure used. – Brian Roach Jan 21 '14 at 01:55
  • I think a[n external] database is going to work better for you. – yshavit Jan 21 '14 at 01:58
  • it was more related to which collection would you use list, set, map and specifically which one of out of those in case of number of elements are huge – blpvivek Jan 27 '14 at 04:48

1 Answers1

1

Welcome to StackExchange. A good place to start would be taking a look at this question:

Difference between HashMap, LinkedHashMap, and SortedMap in Java

HashMap is generally discouraged if you need to grab items in a specific order.

If you need to store 1,000,000+ records, you may want to look into an external database to store the information, as it will be memory consuming to hold all of the records.

Community
  • 1
  • 1
Mike Koch
  • 1,540
  • 2
  • 17
  • 23
  • thanks Mike, I was asked this question in an interview, so I was not sure if database would the perfect answer for this – blpvivek Jan 27 '14 at 04:47
  • What if we don't have any DB to store this much value?can we use hash table and BST in that scenario? – Mohit Singh May 02 '18 at 13:12