Is there any method that does the following for me in one shot:
List<String> list1 = new ArrayList<String>(Arrays.asList("A","B","C","D"));
List<String> list2 = new ArrayList<String>(Arrays.asList("B","C","E","F"));
List<String> list3 = new ArrayList<String>();
for(String element : list2){
if(!list1.contains(element))
list3.add(element);
}
As a result, list3 should contain the elements "E" and "F".
source
share