• <tfoot id='umhTH'></tfoot>
      <bdo id='umhTH'></bdo><ul id='umhTH'></ul>

  • <i id='umhTH'><tr id='umhTH'><dt id='umhTH'><q id='umhTH'><span id='umhTH'><b id='umhTH'><form id='umhTH'><ins id='umhTH'></ins><ul id='umhTH'></ul><sub id='umhTH'></sub></form><legend id='umhTH'></legend><bdo id='umhTH'><pre id='umhTH'><center id='umhTH'></center></pre></bdo></b><th id='umhTH'></th></span></q></dt></tr></i><div id='umhTH'><tfoot id='umhTH'></tfoot><dl id='umhTH'><fieldset id='umhTH'></fieldset></dl></div>
    <legend id='umhTH'><style id='umhTH'><dir id='umhTH'><q id='umhTH'></q></dir></style></legend>
  • <small id='umhTH'></small><noframes id='umhTH'>

        List 和 Set 的性能和内存分配比较

        时间:2023-10-13
        <i id='4SxNc'><tr id='4SxNc'><dt id='4SxNc'><q id='4SxNc'><span id='4SxNc'><b id='4SxNc'><form id='4SxNc'><ins id='4SxNc'></ins><ul id='4SxNc'></ul><sub id='4SxNc'></sub></form><legend id='4SxNc'></legend><bdo id='4SxNc'><pre id='4SxNc'><center id='4SxNc'></center></pre></bdo></b><th id='4SxNc'></th></span></q></dt></tr></i><div id='4SxNc'><tfoot id='4SxNc'></tfoot><dl id='4SxNc'><fieldset id='4SxNc'></fieldset></dl></div>
      1. <legend id='4SxNc'><style id='4SxNc'><dir id='4SxNc'><q id='4SxNc'></q></dir></style></legend>
          <tbody id='4SxNc'></tbody>

          <small id='4SxNc'></small><noframes id='4SxNc'>

              <bdo id='4SxNc'></bdo><ul id='4SxNc'></ul>
              <tfoot id='4SxNc'></tfoot>

                  本文介绍了List 和 Set 的性能和内存分配比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想知道List和Set在性能、内存分配和可用性方面的比较.

                  I want to know the comparison between List and Set in terms of performance,memory allocation and usability.

                  如果我不需要保持对象列表中的唯一性,也不需要维护插入顺序,我可以互换使用 ArrayList 和 SortedSet/HashSet 吗?直接使用 Collections 类而不是 list/set 会更好吗?

                  If i don't have any requirement of keeping the uniqueness in the list of objects, neither required the insertion order to be maintained, Can I use ArrayList and SortedSet/HashSet interchangeably? Will it be good to directly use Collections class instead of even list/set?

                  附:我也不需要列出或设置 java 提供的特定功能.我使用 List/Set 而不是 Array 只是因为它们可以动态增长而无需额外的编程工作.

                  P.S. I also don't have any need for list or set specific functions provided by java. I am using List/Set instead of Array only because they can dynamically grow without extra programming efforts.

                  推荐答案

                  如果你不关心排序,不删除元素,那么归根结底就是你是否需要在这个数据结构中查找元素,以及您需要这些查找的速度.

                  If you don't care about the ordering, and don't delete elements, then it really boils down to whether you need to find elements in this data structure, and how fast you need those lookups to be.

                  HashSet 中按值查找元素是 O(1).在 ArrayList 中,它是 O(n).

                  Finding an element by value in a HashSet is O(1). In an ArrayList, it's O(n).

                  如果您只是使用容器来存储一堆唯一的对象,并在最后迭代它们(以任何顺序),那么可以说 ArrayList 是一个更好的选择,因为它更简单且更多经济实惠.

                  If you are only using the container to store a bunch of unique objects, and iterate over them at the end (in any order), then arguably ArrayList is a better choice since it's simpler and more economical.

                  这篇关于List 和 Set 的性能和内存分配比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:边界匹配器正则表达式 () 上的以下片段问题 下一篇:如何对 HashSet 进行排序?

                  相关文章

                        <bdo id='AunpJ'></bdo><ul id='AunpJ'></ul>
                    1. <small id='AunpJ'></small><noframes id='AunpJ'>

                      <legend id='AunpJ'><style id='AunpJ'><dir id='AunpJ'><q id='AunpJ'></q></dir></style></legend>
                    2. <i id='AunpJ'><tr id='AunpJ'><dt id='AunpJ'><q id='AunpJ'><span id='AunpJ'><b id='AunpJ'><form id='AunpJ'><ins id='AunpJ'></ins><ul id='AunpJ'></ul><sub id='AunpJ'></sub></form><legend id='AunpJ'></legend><bdo id='AunpJ'><pre id='AunpJ'><center id='AunpJ'></center></pre></bdo></b><th id='AunpJ'></th></span></q></dt></tr></i><div id='AunpJ'><tfoot id='AunpJ'></tfoot><dl id='AunpJ'><fieldset id='AunpJ'></fieldset></dl></div>

                      <tfoot id='AunpJ'></tfoot>