I want to get all values that has duplicate from multiple List of Integers. The confusing part is these list of Integers are inside a Map of Map like this LinkedHashMap<String, LinkedHashMap<String, List>> streams
// sample value
{
break_desc100=
{
bDesc_1000=[62, 72, 82, 92, 102, 112, 122],
bDesc 1001=[180, 190, 200, 210, 220, 230, 240],
cMessage_1000=[112],
cMessage_1001=[232]
}
}
// for this one I want to get 112
So far I tried using retainAll but my code doesn't work if the list with duplicate are not next to each other.
for (Map.Entry<String,LinkedHashMap<String,List<Integer>>> entry : streams.entrySet()) {
String currentStream = entry.getKey();
LinkedHashMap<String,List<Integer>> bDescList = entry.getValue();
for (Map.Entry<String,List<Integer>> bDesc : bDescList.entrySet()) {
if (firstIteration) {
prevBDesc = bDesc;
firstIteration = false;
} else {
List<Integer> currentList = prevBDesc.getValue();
List<Integer> nextList = bDesc.getValue();
duplicates = new ArrayList<Integer>(currentList);
duplicates.retainAll(nextList);
allDuplicates.addAll(duplicates); //Set<Integer>
prevBDesc = bDesc;
}
}
}
EDIT: Sorry guys I forgot to add that it is running on Java 1.5.