<small id='ZV2kE'></small><noframes id='ZV2kE'>

          <bdo id='ZV2kE'></bdo><ul id='ZV2kE'></ul>

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

        <legend id='ZV2kE'><style id='ZV2kE'><dir id='ZV2kE'><q id='ZV2kE'></q></dir></style></legend>

        ConcurrentHashMap.newKeySet() 与 Collections.newSetFromMap()

        时间:2023-10-13
        • <tfoot id='ZZ4PA'></tfoot>

          <small id='ZZ4PA'></small><noframes id='ZZ4PA'>

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

          • <bdo id='ZZ4PA'></bdo><ul id='ZZ4PA'></ul>

                  <tbody id='ZZ4PA'></tbody>
                  本文介绍了ConcurrentHashMap.newKeySet() 与 Collections.newSetFromMap()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Java 8 引入了获取并发 Set 实现的新方法

                  Java 8 introduced new way to obtain a concurrent Set implementation

                  // Pre-Java-8 way to create a concurrent set
                  Set<String> oldStyle = Collections.newSetFromMap(new ConcurrentHashMap<>());
                  // New method in Java 8
                  Set<String> newStyle = ConcurrentHashMap.newKeySet();
                  

                  有什么理由更喜欢新方法吗?

                  Is there any reason to prefer new method?

                  有什么优点/缺点?

                  推荐答案

                  ConcurrentHashMap.newKeySet() 应该更高效一些,因为它移除了单层间接.Collections.newSetFromMap(map)主要是基于将操作重定向到map.keySet(),而ConcurrentHashMap.newKeySet()则非常接近 map.keySet() 本身(仅具有附加支持).

                  ConcurrentHashMap.newKeySet() should be somewhat more efficient as removes a single level of indirection. Collections.newSetFromMap(map) is mostly based on redirecting the operations to the map.keySet(), but ConcurrentHashMap.newKeySet() is very close to map.keySet() itself (just with additions support).

                  至于功能,我认为没有区别.

                  As for functionality, I see no difference.

                  这篇关于ConcurrentHashMap.newKeySet() 与 Collections.newSetFromMap()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从 Java Set 中获取 *any* 值的好方法? 下一篇:泛型地狱:我可以构造一个 TypeLiteral&lt;Set&lt;T&gt;&gt;

                  相关文章

                  • <bdo id='Wtqex'></bdo><ul id='Wtqex'></ul>

                  1. <small id='Wtqex'></small><noframes id='Wtqex'>

                    <tfoot id='Wtqex'></tfoot>

                    <legend id='Wtqex'><style id='Wtqex'><dir id='Wtqex'><q id='Wtqex'></q></dir></style></legend>

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