英文:
can i prevent use List with ResultSet?
问题
通常使用List来存储resultSet是常见的做法,但我在一些文章中看到,当处理大数据时,其性能会变慢,建议使用HashMap来代替。我现在感到困惑,这方面有什么建议吗?
英文:
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?
答案1
得分: 1
List
(列表)和Map
(映射)是不同的数据结构,它们被设计用于不同的目的。与其解释它们,我建议您仔细阅读文档,文档中已经提供了足够详细的信息。
在Java中,List
有多种实现。只要您存储和读取值,ArrayList
就能够满足性能要求,即使在非常大的数据集情况下也是如此。然而,如果您的需求还包括频繁地删除元素,您应该使用LinkedList
而不是ArrayList
。当您从ArrayList
中删除一个元素时,所有后续元素都会在列表中向下移动一个位置,而在LinkedList
的情况下,它只需要更改一个链接(现在在删除的元素之前的项链接到删除的元素旁边的项)。
英文:
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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论