我想知道比较这两个 HashMap 的最佳方法。我想验证它们是否相同,如果不相同,有什么区别。如果它很重要,那么我想知道第二个有/没有第一个 hashmap 有什么。我需要知道一个键是否有另一个键,以及每个键的值列表差异。我希望有一种简单的方法来映射它,但不确定。基本示例:
HashMap<String, List<String>> hmOne = new HashMap<String, List<String>>();
List<String>l1 = new ArrayList<String>();
l1.add("one");
l1.add("two");
l1.add("three");
l1.add("four");
l1.add("five");
hmOne.put("firstkey", l1);
l1 = new ArrayList<String>();
l1.add("1");
l1.add("2");
l1.add("3");
l1.add("4");
l1.add("5");
hmOne.put("secondkey", l1);
HashMap<String, List<String>> hmTwo = new HashMap<String, List<String>>();
List<String>l2 = new ArrayList<String>();
l2.add("one");
l2.add("two");
l2.add("four");
l2.add("five");
hmTwo.put("firstkey", l2);
l2 = new ArrayList<String>();
l2.add("1");
l2.add("3");
l2.add("4");
l2.add("5");
hmTwo.put("secondkey", l2);
感谢您的帮助。
最佳答案
关于Java HashMap<String,List<String>>() 比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7826299/