Java asymmetric set difference

If you need to find difference between two sets you can use method removeAll. The difference will be kept only on the set which is calling the method. Definition: booleanremoveAll(Collection<?> c) Description: Removes from this set all of its elements that are contained in the specified collection (optional operation). If the specified collection is also a … Read more

Java intersection of Sets

If you need to get only the elements which are common for two sets you can use the method retainAll. The documentation for this method states: “Method signature: boolean retainAll(Collection<?> c) Description: Retains only the elements in this set that are contained in the specified collection (optional operation). In other words, removes from this set all … Read more