, , a.removeAll(b);. removeAll() Java-API.
: - O (n ^ 2), , ( - , ). , . removeAll() . , Hash, , , . , , , - , HashSet.: -)
: , , Java. removeAll() - Java-API, ( - ) . , - , for-loops . , . ( ), ( O (n)):
int bIndex = 0;
for(int i = 0 ; i < a.size(); i++) {
while (a[i] < b[bIndex]) {bIndex++;}
if (a[i] == b[bIndex]) {markForRemoval(a[i]);}
}
, , b. .