I am trying to compare the Key value pairs of an hash map where the value order is not same as i am reading the map1 from one source and map2 from another source. The keys will be same but the order list will be in a different order.
The comparison is resulting fail, which i need to fix it
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();
}
}
How can i fix this so my comparision is successful