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

    <legend id='VtCfi'><style id='VtCfi'><dir id='VtCfi'><q id='VtCfi'></q></dir></style></legend>
    <tfoot id='VtCfi'></tfoot>

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

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

        如何对 HashSet 进行排序?

        How to sort a HashSet?(如何对 HashSet 进行排序?)
        <i id='lUCq2'><tr id='lUCq2'><dt id='lUCq2'><q id='lUCq2'><span id='lUCq2'><b id='lUCq2'><form id='lUCq2'><ins id='lUCq2'></ins><ul id='lUCq2'></ul><sub id='lUCq2'></sub></form><legend id='lUCq2'></legend><bdo id='lUCq2'><pre id='lUCq2'><center id='lUCq2'></center></pre></bdo></b><th id='lUCq2'></th></span></q></dt></tr></i><div id='lUCq2'><tfoot id='lUCq2'></tfoot><dl id='lUCq2'><fieldset id='lUCq2'></fieldset></dl></div>
          <bdo id='lUCq2'></bdo><ul id='lUCq2'></ul>

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

              <tfoot id='lUCq2'></tfoot>

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

                    <tbody id='lUCq2'></tbody>
                  本文介绍了如何对 HashSet 进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  对于列表,我们使用 Collections.sort(List) 方法.如果我们想对 HashSet 进行排序怎么办?

                  For lists, we use the Collections.sort(List) method. What if we want to sort a HashSet?

                  推荐答案

                  HashSet 不保证其元素的任何顺序.如果您需要此保证,请考虑使用 TreeSet 来保存您的元素.

                  A HashSet does not guarantee any order of its elements. If you need this guarantee, consider using a TreeSet to hold your elements.

                  但是,如果您只需要针对这一事件对元素进行排序,则只需临时创建一个 List 并对其进行排序:

                  However if you just need your elements sorted for this one occurrence, then just temporarily create a List and sort that:

                  Set<?> yourHashSet = new HashSet<>();
                  
                  ...
                  
                  List<?> sortedList = new ArrayList<>(yourHashSet);
                  Collections.sort(sortedList);
                  

                  这篇关于如何对 HashSet 进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 中的默认语言环境设置以使其保持一致?)

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

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

                        <tfoot id='y5MzY'></tfoot>
                          <legend id='y5MzY'><style id='y5MzY'><dir id='y5MzY'><q id='y5MzY'></q></dir></style></legend>

                              <tbody id='y5MzY'></tbody>