Here you can find the source of addAllUnique(final Collection collection, final Collection values)
Parameter | Description |
---|---|
collection | the collection. |
values | the values. |
public static boolean addAllUnique(final Collection collection, final Collection values)
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { /**// ww w.j a v a 2s . com * add a collection of values to a collection. * * @param collection * the collection. * @param values * the values. * @return boolean. * @since 0.1 */ public static boolean addAllUnique(final Collection collection, final Collection values) { boolean changed = false; for (final Iterator iter = values.iterator(); iter.hasNext();) { changed = addUnique(collection, iter.next()); } return changed; } /** * add a unique value to a collection. If the value already exists, it will * return <code>false</code>. * * @param collection * the collection. * @param value * the value. * @return boolean. * @since 0.1 */ public static boolean addUnique(final Collection collection, final Object value) { if (collection.contains(value)) { return false; } return collection.add(value); } }