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

      1. <tfoot id='EokpF'></tfoot>

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

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

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

        在java中获得两组之间对称差异的最佳方法是什么?

        What is the best way get the symmetric difference between two sets in java?(在java中获得两组之间对称差异的最佳方法是什么?)

            <tbody id='G2Thp'></tbody>
        • <tfoot id='G2Thp'></tfoot>

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

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

                1. 本文介绍了在java中获得两组之间对称差异的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想知道是否有一种快速/干净的方法来获得两组之间的对称差异?

                  I'm wondering if there is a quick/clean way to get the symmetric difference between two sets ?

                  我有:

                  Set<String> s1 = new HashSet<String>();
                  s1.add("a");
                  s1.add("b");
                  s1.add("c");
                  
                  Set<String> s2 = new HashSet<String>();
                  s2.add("b");
                  

                  我需要类似的东西:

                  Set<String> diff = Something.diff(s1, s2);
                  // diff would contain ["a", "c"]
                  

                  <小时>

                  只是为了澄清我需要对称差异.

                  推荐答案

                  你可以使用 Google Guava 库(真的很棒,我强烈推荐它!):

                  You can use some functions from the Google Guava library (which is really great, I strongly recommend it!):

                  Sets.difference(s1, s2);
                  Sets.symmetricDifference(s1, s2);
                  

                  difference() 和 symmetricDifference()

                  symmetricDifference() 完全符合 您的要求,但 difference() 通常也很有帮助.

                  symmetricDifference() does exactly what you are asking for, but difference() is also often helpful.

                  这两种方法都返回实时视图,但您可以例如在结果集上调用 .immutableCopy() 以获得不变集.如果您不想要视图,但需要一个可以修改的集合实例,请调用 .copyInto(s3).请参阅 SetView 对于这些方法.

                  Both methods return a live view, but you can for example call .immutableCopy() on the resulting set to get a non-changing set. If you don't want a view, but need a set instance you can modify, call .copyInto(s3). See SetView for these methods.

                  这篇关于在java中获得两组之间对称差异的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Compiling C++ for the JVM(为 JVM 编译 C++)
                  Compile to java bytecode (without using Java)(编译成java字节码(不使用Java))
                  How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?(如何在编译时驱动 C#、C++ 或 Java 编译器计算 1+2+3+...+1000?)
                  Java ClassLoader: load same class twice(Java ClassLoader:两次加载相同的类)
                  How to debug .class files in ECLIPSE?(如何在 ECLIPSE 中调试 .class 文件?)
                  Java quot;The blank final field may not have been initializedquot; Anonymous Interface vs Lambda Expression(Java“可能尚未初始化空白的最终字段匿名接口与 Lambda 表达式)
                  1. <legend id='jPARc'><style id='jPARc'><dir id='jPARc'><q id='jPARc'></q></dir></style></legend>
                  2. <small id='jPARc'></small><noframes id='jPARc'>

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

                      • <bdo id='jPARc'></bdo><ul id='jPARc'></ul>
                          <tbody id='jPARc'></tbody>

                          <tfoot id='jPARc'></tfoot>