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

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

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

      1. 如何获得两个地图Java之间的差异?

        How to get the difference between two maps Java?(如何获得两个地图Java之间的差异?)

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

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

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

                  本文介绍了如何获得两个地图Java之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有两张地图如下:

                  Map<String, Record> sourceRecords;
                  Map<String, Record> targetRecords;
                  

                  我想获得与每个地图不同的键.即

                  I want to get the keys differ from each of the maps.i.e.

                  1. 它显示 sourceRecords 中可用但 targetRecords 中不可用的映射键.
                  2. 它显示 targetRecords 中可用但 sourceRecords 中不可用的映射键.

                  我是这样做的:

                  Set<String> sourceKeysList = new HashSet<String>(sourceRecords.keySet());
                  Set<String> targetKeysList = new HashSet<String>(targetRecords.keySet());
                  
                  SetView<String> intersection = Sets.intersection(sourceKeysList, targetKeysList);
                  Iterator it = intersection.iterator();
                  while (it.hasNext()) {
                      Object object = (Object) it.next();
                      System.out.println(object.toString());
                  }
                  
                  SetView<String> difference = Sets.symmetricDifference(sourceKeysList, targetKeysList);
                  ImmutableSet<String> immutableSet = difference.immutableCopy();
                  

                  编辑

                  if(sourceKeysList.removeAll(targetKeysList)){
                              //distinct sourceKeys
                              Iterator<String> it1 = sourceKeysList.iterator();
                              while (it1.hasNext()) {
                                  String id = (String) it1.next();
                                  String resultMessage = "This ID exists in source file but not in target file";
                                  System.out.println(resultMessage);
                                  values = createMessageRow(id, resultMessage);
                                  result.add(values);
                              }
                          }
                          if(targetKeysList.removeAll(sourceKeysList)){
                              //distinct targetKeys
                              Iterator<String> it1 = targetKeysList.iterator();
                              while (it1.hasNext()) {
                                  String id = (String) it1.next();
                                  String resultMessage = "This ID exists in target file but not in source file";
                                  System.out.println(resultMessage);
                                  values = createMessageRow(id, resultMessage);
                                  result.add(values);
                              }
                          }
                  

                  我能够找到公共键,但不能找到不同的键.请帮忙.

                  I am able to find the common keys but not distinct keys. Please help.

                  推荐答案

                  集合也允许您删除元素.

                  如果生成帮助"集对您来说不是问题(因为条目太多;那么:

                  If generating "helper" sets is not a problem for you (because of too many entries; what about:

                  Set<String> sources = get a copy of all source entries
                  Set<String> targets = get a copy of all source entries
                  

                  然后:

                  sources.removeAll(targets) ... leaves only entries in sources that are only in sources, not in target
                  

                  sources.retainAll(targets) ... leaves only entries that are in both sets
                  

                  您可以从这里开始工作......

                  You can work your way from here ...

                  这篇关于如何获得两个地图Java之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

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

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

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

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

                          <bdo id='bRidN'></bdo><ul id='bRidN'></ul>
                            <tfoot id='bRidN'></tfoot>