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?
-
This is very vague: please provide references to the place(s) where you have read this.Andy Turner– Andy Turner2020-05-04 20:38:03 +00:00Commented May 4, 2020 at 20:38
-
3List is an interface. There are no performance implications with it. It just holds data in a sequence somehow (through various implementations).George– George2020-05-04 20:38:51 +00:00Commented May 4, 2020 at 20:38
-
stackoverflow.com/questions/18862997/… and some otherJAAFAR– JAAFAR2020-05-05 08:10:19 +00:00Commented May 5, 2020 at 8:10
1 Answer
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).
2 Comments
ArrayList than with HashMap. By any chance have you checked this Q/A?