Here you can find the source of contains(Collection collection, A value)
Parameter | Description |
---|---|
A | Key type |
collection | Input collection |
value | Value to search |
public static <A> boolean contains(Collection<A> collection, A value)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Pablo Pavon-Marino. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl.html * * Contributors:/*from w w w.j a v a2 s . c o m*/ * Pablo Pavon-Marino - Jose-Luis Izquierdo-Zaragoza, up to version 0.3.1 * Pablo Pavon-Marino - from version 0.4.0 onwards ******************************************************************************/ import java.util.*; public class Main { /** * Checks if an input collection contains a given value. * * @param <A> Key type * @param collection Input collection * @param value Value to search * @return {@code true} if {@code value} is present in {@code collection}, and {@code false} otherwise. If {@code collection} is empty, it will return {@code false} */ public static <A> boolean contains(Collection<A> collection, A value) { if (collection.isEmpty()) return false; for (A item : collection) if (item == value) return true; return false; } }