I have two ArrayList as follows:
ArrayList
original: 12, 16, 17, 19, 101
12, 16, 17, 19, 101
selected: 16, 19, 107, 108, 109
16, 19, 107, 108, 109
Using Guava library:
List listA = Lists.newArrayList(12,16,17,19,101); List listB = Lists.newArrayList(16,19,107,108,109); Set intersection = Sets.intersection(Sets.newHashSet(listA), Sets.newHashSet(listB)); listA.removeAll(intersection); listB.removeAll(intersection);