我可以阻止使用 ResultSet 来操作 List 吗?

huangapple go评论63阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年5月5日 04:33:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/61601104.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定