i have two lists ListOne and ListTwo. I have to find out all the elements of ListOne which does not exist in ListTwo. Similarly I have to find out all the elements of ListTwo which does not exist in ListOne .
My below code is working , but i am thinking there might be some better way
List<Long> listOne=...Some valid values;
List<Long> listTwo=...Some valid values;
List<Long> listThree=new ArrayList<Long>();
List<Long> listFour=new ArrayList<Long>();
for (Long id: ListOne) {
if(!listTwo.contains(id)){
listThree.add(id);
}
}
for (Long id: ListTwo) {
if(!listOne.contains(id)){
listFour.add(id);
}
}