我正在尝试比较哈希映射的键值对,其中值顺序与我从一个源读取 map1 和从另一个源读取 map2 不同。键将相同,但订单列表将采用不同的顺序。
比较导致失败,我需要修复它
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
public class TestClass {
private static Map<String, List<String>> tempMap;
private static Map<String, List<String>> tempMap1;
private static Map<String, List<String>> tempMap2;
private static Map<String, List<String>> tempMap3;
public static Map<String, List<String>> practiceMap(){
tempMap = new HashMap<String, List<String>>();
List<String> completeDateKey = new ArrayList<>();
List<String> statusKey = new ArrayList<String>();
List<String> completeDateValue = new ArrayList<String>();
List<String> statusValue = new ArrayList<String>();
ArrayList<String> key = new ArrayList<String>(Arrays.asList("Complete Date", "Status"));
ArrayList<String> completedate = new ArrayList<String>(Arrays.asList("", "11/15/2019"));
ArrayList<String> status = new ArrayList<String>(Arrays.asList("NEW", "CLOSE"));
completeDateKey.add(key.get(0));
statusKey.add(key.get(1));
completeDateValue.addAll(completedate);
statusValue.addAll(status);
tempMap.put(completeDateKey.toString(), completeDateValue);
tempMap.put(statusKey.toString(), statusValue);
return tempMap;
}
public static Map<String, List<String>> practiceMap1(){
tempMap1 = new HashMap<String, List<String>>();
List<String> completeDateKey = new ArrayList<>();
List<String> statusKey = new ArrayList<String>();
List<String> completeDateValue = new ArrayList<String>();
List<String> statusValue = new ArrayList<String>();
ArrayList<String> key = new ArrayList<String>(Arrays.asList("Complete Date", "Status"));
ArrayList<String> completedate = new ArrayList<String>(Arrays.asList("11/15/2019", ""));
ArrayList<String> status = new ArrayList<String>(Arrays.asList("CLOSE", "NEW"));
completeDateKey.add(key.get(0));
statusKey.add(key.get(1));
completeDateValue.addAll(completedate);
statusValue.addAll(status);
tempMap1.put(completeDateKey.toString(), completeDateValue);
tempMap1.put(statusKey.toString(), statusValue);
return tempMap1;
}
public static void comparisionTest() {
tempMap3 = new HashMap<String, List<String>>();
tempMap2 = new HashMap<String, List<String>>();
tempMap2 = practiceMap();
tempMap3 = practiceMap1();
System.out.println("map 1 is " + tempMap2);
System.out.println("map 2 is " + tempMap3);
int size = practiceMap().size();
System.out.println(size);
if(tempMap2.equals(tempMap3) == true) { System.out.println("Successful"); }
else { System.out.println("failed"); }
}
public static void main(String[] args) {
new TestClass().comparisionTest();
}
}
我该如何解决这个问题,以便我的比较成功