Java tutorial
//package com.java2s; import java.util.Collection; public class Main { public static <T> void addIfNotExist(T item, Collection<T> col) { if (!col.contains(item)) { col.add(item); } } /** * Check if an array to see if it contains a single value * * @param item * @param array * @return */ public static <T> boolean contains(T item, T[] array) { for (T t : array) { if (t == item) { return true; } } return false; } }