• <bdo id='I1Fjn'></bdo><ul id='I1Fjn'></ul>
      <tfoot id='I1Fjn'></tfoot><legend id='I1Fjn'><style id='I1Fjn'><dir id='I1Fjn'><q id='I1Fjn'></q></dir></style></legend>

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

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

        按所有对象包含的字符串值对 Set 中的对象进行排序

        Sorting objects within a Set by a String value that all objects contain(按所有对象包含的字符串值对 Set 中的对象进行排序)
        <legend id='5opQr'><style id='5opQr'><dir id='5opQr'><q id='5opQr'></q></dir></style></legend>
        <i id='5opQr'><tr id='5opQr'><dt id='5opQr'><q id='5opQr'><span id='5opQr'><b id='5opQr'><form id='5opQr'><ins id='5opQr'></ins><ul id='5opQr'></ul><sub id='5opQr'></sub></form><legend id='5opQr'></legend><bdo id='5opQr'><pre id='5opQr'><center id='5opQr'></center></pre></bdo></b><th id='5opQr'></th></span></q></dt></tr></i><div id='5opQr'><tfoot id='5opQr'></tfoot><dl id='5opQr'><fieldset id='5opQr'></fieldset></dl></div>

          <tbody id='5opQr'></tbody>

            <bdo id='5opQr'></bdo><ul id='5opQr'></ul>

            <tfoot id='5opQr'></tfoot>

            <small id='5opQr'></small><noframes id='5opQr'>

                1. 本文介绍了按所有对象包含的字符串值对 Set 中的对象进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  好的,这是一个棘手的问题.我有一个集合列表.我想按顺序对集合中的对象进行排序.

                  Ok this is a tricky one. I have a list of Sets. I would like to sort the objects in the Sets in an order.

                  将每个集合想象成代表学校的一个班级.每个集合都包含人员对象.一个人对象持有一个字符串值作为名称.我想在循环并写出之前按名称排列 Set 中的 Persons.

                  Imagine each set as repressenting a class in a school. Each set contains person objects. A person object holds a String value for name. I'd like to arrange the Persons in the Set by name before I loop through and write them out.

                  有没有办法使用 Collections.sort(); 或类似的东西来实现这一点?

                  Is there anywahy to use Collections.sort(); or something similar to achieve this?

                  for (Set<Person> s : listOfAllChildren) {       
                        for (Person p : s) {
                          if(p.getClass().equalsIgnoreCase("Jones")){
                            System.out.println(p.getName());
                            }
                           else if...//carry on through other classes 
                          }                              
                        }        
                  

                  我知道一个班有 2 个以上的孩子可能有相同的名字,但请忽略这个

                  推荐答案

                  一个 Set 没有 ordering 的概念,因为它是一个集合.

                  A Set has no notion of ordering because, well, it's a set.

                  TreeSet 类实现的SortedSet 接口可以使用.只需向构造函数提供适当的 Comparator,或让您的 Person 类实现 Comparable.

                  There is a SortedSet interface implemented by TreeSet class that you can use. Simply provide an appropriate Comparator to the constructor, or let your Person class implements Comparable.

                  这篇关于按所有对象包含的字符串值对 Set 中的对象进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

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

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

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

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