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?

3
  • This is very vague: please provide references to the place(s) where you have read this. Commented May 4, 2020 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). Commented May 4, 2020 at 20:38
  • stackoverflow.com/questions/18862997/… and some other Commented May 5, 2020 at 8:10

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

2 Comments

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?
When it comes to retrieving data, the performance will be better with ArrayList than with HashMap. By any chance have you checked this Q/A?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.