Java tutorial
//package com.java2s; /* * File: $RCSfile$ * * Copyright (c) 2005 Wincor Nixdorf International GmbH, * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany * All Rights Reserved. * * This software is the confidential and proprietary information * of Wincor Nixdorf ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered * into with Wincor Nixdorf. */ import java.util.List; public class Main { /** * Safety add one element into collection, if collection contains specified object, it doesn't add it * * @param collection specified collection * @param object specified object * @return @see java.util.List#add */ public static boolean safeAdd(List collection, Object object) { return !collection.contains(object) && collection.add(object); } }