Here you can find the source of addUnique(final Collection collection, final Object value)
Parameter | Description |
---|---|
collection | the collection. |
value | the value. |
public static boolean addUnique(final Collection collection, final Object value)
//package com.java2s; import java.util.Collection; public class Main { /**/*from ww w. java 2s .com*/ * 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); } }