Here you can find the source of countComplement(Collection extends T> s1, Collection extends T> s2)
public static <T extends Object> int countComplement(Collection<? extends T> s1, Collection<? extends T> s2)
//package com.java2s; import java.util.*; public class Main { public static <T extends Object> int countComplement(Collection<? extends T> s1, Collection<? extends T> s2) { int n1 = s1.size(); int n2 = s2.size(); if (n2 < n1) { Collection<? extends T> t = s1; s1 = s2;/*from w w w .j av a2 s. com*/ s2 = t; } int n = s2.size() - s1.size(); for (T e : s1) { if (!s2.contains(e)) n++; } return n; } public static int size(Collection<?> c) { return (c == null) ? 0 : c.size(); } }