@Test
    public void testRetainAll() {
        final List<String> stuff = doubleAdd();
        final TinyIdentitySet<String> t = new TinyIdentitySet<>(
                stuff.size());
        t.addAll(stuff);
        assertFalse(t.retainAll(stuff));
        assertEquals(stuff.size() / 2, t.size());
        t.add("nalle");
        assertEquals(stuff.size() / 2 + 1, t.size());
        assertTrue(t.retainAll(stuff));
        assertEquals(stuff.size() / 2, t.size());
    }
Check TinyIdentitySet seems to work. :)

@author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
vespajlib/src/test/java/com/yahoo/collections/TinyIdentitySetTestCase.java