!modifier.contains(key)
is always true, it can be removed from your if-statement.modifier.size() == 0
can be replaced withmodifier.isEmpty()
.- Since you seem to want to add duplicates from File B, you need to check File A, not
finalPNList
when checking for existence (I just checked the applicable list inmasterList
, feel free to change this to something more appropriate / efficient). - You need to have an
else
after your first if-statement, otherwise you're adding items from File A twice. - I assumed you just missed
456
in your output, otherwise I might not quite understand.
Modified code with your file-IO replaced with something that's more in the spirit of an SSCCE:
masterList.put("A", Arrays.asList("123","123","456"));
masterList.put("B", Arrays.asList("123","789","789"));
for (Map.Entry<String, List<String>> e : masterList.entrySet()) {
String key = e.getKey();
List<String> val = e.getValue();
System.out.println(modifier.size());
for (String s : val) {
if (modifier.isEmpty())
finalPNList.add(s);
else if (!modifier.isEmpty() && masterList.get("A").contains(s)) {
// s has been added by parent process so SKIP!
skipped.add(s);
} else
finalPNList.add(s);
}
modifier.add(key);
}
Test.