/** * Removes any values in the set which are not contained in * <tt>collection</tt>. * * @param collection a <code>Collection</code> value * @return true if the set was modified by the retain all operation */ public boolean retainAll(Collection collection) { boolean changed = false; int size = size(); Iterator it; it = iterator(); while (size-- > 0) { if (! collection.contains(it.next())) { it.remove(); changed = true; } } return changed; }
/** * Returns a typed array of the objects in the set. * * @param a an <code>Object[]</code> value * @return an <code>Object[]</code> value */ public Object[] toArray(Object[] a) { int size = size(); if (a.length < size) a = (Object[])java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); forEach(new ToObjectArrayProcedure(a)); Iterator it = iterator(); for (int i=0; i<size; i++) { a[i] = it.next(); } if (a.length > size) { a[size] = null; } return a; }