I have two array lists e.g.
List<Date> a; contains : 10/10/2014, 10/11/2016 List<Date> b; contains : 10/10/2016
How can i do a check between list a
and b
so the value that is missing in b
is returned?e.g. 10/10/2014
Method 6: Use symmetric_difference to Find the Difference Between Two Lists in Python. The elements that are either in the first set or the second set are returned using the symmetric_difference() technique. The intersection, unlike the shared items of the two sets, is not returned by this technique.
Using the Java List API. We can create a copy of one list and then remove all the elements common with the other using the List method removeAll(): List<String> differences = new ArrayList<>(listOne); differences. removeAll(listTwo); assertEquals(2, differences.
Use Numpy to Subtract Two Python Lists One of the methods that numpy provides is the subtract() method. The method takes two numpy array s as input and provides element-wise subtractions between the two lists.
You can convert them to Set
collections, and perform a set difference operation on them.
Like this:
Set<Date> ad = new HashSet<Date>(a); Set<Date> bd = new HashSet<Date>(b); ad.removeAll(bd);
If you only want find missing values in b, you can do:
List toReturn = new ArrayList(a); toReturn.removeAll(b); return toReturn;
If you want to find out values which are present in either list you can execute upper code twice. With changed lists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With