How can I know the different element between 2 array list in java? I need the exact element not a Boolean value which can be retrieved using removeAll()
.
It depends on what do you want to check.
If you want to get all the unique elements for both lists (i.e. sum of all elements that are unique for the first list and all elements that unique for the second list) also known as symmetric difference you can use as mentioned above disjunction method from Apache Commons Collections 4.0:
CollectionUtils.disjunction(a, b);
If you want to get all unique elements only from one list (i.e. elements that exist only in one list, but don't exist in the other) also known as relative complement you can subtract from this list the other one using subtract method from Apache Commons Collections 4.0:
CollectionUtils.subtract(a, b); //gives all unique elements of a that don't exist in b