How to get a difference of one int list/array to another

Hello everyone,

I have two lists/arrays of variable size A, B and I would like to get everything extra a list B might have, that list A does not.

public int a = {2,2,3,2,0};
public int b = {3,2,1};
---------------> 1

I have found some java code, however I could not figure out how to implement it :

Set<Date> ad = new HashSet<Date>(a);
Set<Date> bd = new HashSet<Date>(b);
ad.removeAll(bd);

and

List toReturn = new ArrayList(a);
toReturn.removeAll(b);

return toReturn;

Hopefully it’s not too stupid of a question since I could not find it anywhere.

Thank you for any thoughts on this !

1 Like

some “pseudo” code:

for (int i = 0; i< B.length; i++) {
  if (!A.hasValue(B.get(i))) {
    C.add(B.get(i));
  }
}

for each element of B:
if element of B at index I is NOT in A
add it to C

-> C contains all values in B that are not in A

1 Like

Ahhh, thank you so much !
I can’t believe I have missed that in the documentation.

happens to all of us :smiley: