Is possible to compare many maps stored in an arrayList?
I mean:
public static void main(String[] args) {
List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
Map<String, Object> entry1 = new HashMap<>();
Map<String, Object> entry2 = new HashMap<>();
Map<String, Object> entry3 = new HashMap<>();
Map<String, Object> entry4 = new HashMap<>();
entry1.put("entity1", "19820271");
entry2.put("entity1", "19820271");
entry3.put("entity2", "19820272");
entry4.put("entity2", "19820272");
mapList.add(entry1);
mapList.add(entry2);
mapList.add(entry3);
mapList.add(entry4);
groupMaps(mapList);
}
private static List<Map<String, Object>> groupMaps(List<Map<String, Object>> mapList) {
List<Map<String, Object>> resultante = new ArrayList<>();
for (int i = 0; i < mapList.size(); i++) {
Map<String, Object> map1= mapList.get(0);
for (Map.Entry<String, Object> entry : mapList.get(i).entrySet()) {
if (entry.getValue().equals(map1.get("entity"))) {
resultante.add(mapList.get(i));
}
}
}
return mapList;
}
In the "groupMaps" method I need to compare each map so I can group by match, for example:
map1 matches map2
map3 matches map7
map4 matches map5
and so on...
Is there any way to do it?