0

It is common to use an List to store the resultSet, but I have read in some articles its performance becomes slow with big data and it is recommended to use the HashMap instead. I am confused now, is there any advice in this regard?

JAAFAR
  • 21
  • 1
  • This is very vague: please provide references to the place(s) where you have read this. – Andy Turner May 04 '20 at 20:38
  • 3
    List is an interface. There are no performance implications with it. It just holds data in a sequence somehow (through various implementations). – George May 04 '20 at 20:38
  • https://stackoverflow.com/questions/18862997/using-arraylist-or-hashmap-for-better-speed/18863041 and some other – JAAFAR May 05 '20 at 08:10

1 Answers1

1

List and Map are different data structures and have been designed for different purposes. Instead of explaining them, I suggest you go through the documentation which is sufficiently detailed.

List has various implementations in Java. As long as you are storing and reading the values, an ArrayList is capable to fulfil the performance requirements even with a really big dataset. However, if your requirement is to also delete elements frequently, you should use a LinkedList instead of an ArrayList. When you delete an element from an ArrayList all the subsequent elements are shifted one place down in the list while in case of a LinkedList it requires only a change in one link (now the item before the deleted item links to the item next to the deleted item).

Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110
  • This seems clear, but the reason for my question is that in the case of the List in the big data you should look at each index while the HashMap only gives the key and it's over Is this logic correct? – JAAFAR May 05 '20 at 08:16
  • When it comes to retrieving data, the performance will be better with `ArrayList` than with `HashMap`. By any chance have you checked [this](https://stackoverflow.com/questions/26809537/arraylist-get-faster-than-hashmap-get) Q/A? – Arvind Kumar Avinash May 05 '20 at 10:14