Java examples for java.util:Collection Element
add to Collection if Not Exists
//package com.book2s; import java.util.Collection; public class Main { public static void main(String[] argv) { Collection c = java.util.Arrays.asList("asdf", "book2s.com"); Object obj = "book2s.com"; addNotExists(c, obj);//from w ww .j a va 2 s . c om } public static void addNotExists(Collection<Object> c, Object obj) { if (!c.contains(obj)) { c.add(obj); } } }