0
public static void main(String[] args) {
Hashtable<String, String> ht1= new Hashtable<>();
ht1.put("10", ghu");
ht1.put("20", "lo");


Hashtable<String, String> ht2= new Hashtable<>();
ht2.put("10", "ko");
ht2.put("20", "lo");

我如何通过使用键值对相互比较两个哈希表从两个哈希表中找到键值对的唯一条目..

预期输出...(“10”,“ghu”);这是来自第一个哈希表(“10”,“ko”);这是来自第二个哈希表

4

1 回答 1

0

HashTable 保留一个条目,可以使用 getEntrySet() 方法提取该条目。因此,您应该类似于下面的伪代码。您可能需要对以下代码段进行一些更改以使其可编译。

Set<Entry> entrySet= ht1.getEntrySet();//get all values
      //iterate over those
      for(Entry entry :entrySet ){
            String htVal = ht2.get(entry.getKey());
             if (htval!=null && htVal.equals(entry.getValue())){
                //non unique -ignore
                   }else{
                //store ht1 and ht2 unique entries
                  }
              }
于 2020-04-04T14:03:32.987 回答