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

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

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

    1. 从 Java Set 中获取 *any* 值的好方法?

      Good way to get *any* value from a Java Set?(从 Java Set 中获取 *any* 值的好方法?)
      <i id='kHjZx'><tr id='kHjZx'><dt id='kHjZx'><q id='kHjZx'><span id='kHjZx'><b id='kHjZx'><form id='kHjZx'><ins id='kHjZx'></ins><ul id='kHjZx'></ul><sub id='kHjZx'></sub></form><legend id='kHjZx'></legend><bdo id='kHjZx'><pre id='kHjZx'><center id='kHjZx'></center></pre></bdo></b><th id='kHjZx'></th></span></q></dt></tr></i><div id='kHjZx'><tfoot id='kHjZx'></tfoot><dl id='kHjZx'><fieldset id='kHjZx'></fieldset></dl></div>
      • <bdo id='kHjZx'></bdo><ul id='kHjZx'></ul>

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

              <legend id='kHjZx'><style id='kHjZx'><dir id='kHjZx'><q id='kHjZx'></q></dir></style></legend>
                <tbody id='kHjZx'></tbody>
              <tfoot id='kHjZx'></tfoot>
              • 本文介绍了从 Java Set 中获取 *any* 值的好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                给定一个简单的 Set<T>,从 Set 获取 any 值的好方法是什么(快速,几行代码)代码>?

                Given a simple Set<T>, what is a good way (fast, few lines of code) to get any value from the Set?

                有了List,很简单:

                List<T> things = ...;
                return things.get(0);
                

                但是,对于 Set,没有 .get(...) 方法,因为 Set 没有顺序.

                But, with a Set, there is no .get(...) method because Sets are not ordered.

                推荐答案

                一个 Set 是一个 Iterable,所以迭代到第一个元素是可行的:

                A Set<T> is an Iterable<T>, so iterating to the first element works:

                Set<T> things = ...;
                return things.iterator().next();
                

                Guava 有 一种方法 来做到这一点,虽然上面的代码片段 可能更好.

                Guava has a method to do this, though the above snippet is likely better.

                这篇关于从 Java Set 中获取 *any* 值的好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                <tfoot id='kb7cN'></tfoot>
                      <bdo id='kb7cN'></bdo><ul id='kb7cN'></ul>

                          <tbody id='kb7cN'></tbody>

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

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