Here you can find the source of contains(List
Parameter | Description |
---|---|
list | the list to check |
string | the string |
public static boolean contains(List<String> list, String string)
//package com.java2s; //License from project: Open Source License import java.util.List; import java.util.Set; public class Main { /**/* w w w . j ava 2 s. com*/ * This method checks if the list contains the given string (case sensitive). * * @param list * the list to check * @param string * the string * @return true/false */ public static boolean contains(List<String> list, String string) { if (isNotEmpty(list)) { for (String item : list) { if ((item != null && string != null && item.compareTo(string) == 0) || (item == null && string == null)) { return true; } } } return false; } /** * Check if set isn't empty. * * @param set * The set to be tested. * @return <code>true</code> is not empty, <code>false</code> otherwise. */ public static <E> boolean isNotEmpty(Set<E> set) { return set != null && !set.isEmpty(); } /** * This method checks if the list is not null and have elements. * * @param <E> * * @param list * the list to check * @return true/false */ public static <E> boolean isNotEmpty(List<E> list) { return list != null && !list.isEmpty(); } /** * This method checks if the list is not null and have elements. * * @param <E> * * @param list * the list to check * @return true/false */ public static <E> boolean isNotEmpty(E[] list) { return list != null && list.length > 0; } /** * Check if set is empty. * * @param set * @return */ public static <E> boolean isEmpty(Set<E> set) { return !isNotEmpty(set); } public static <E> boolean isEmpty(List<E> list) { return !isNotEmpty(list); } public static <E> boolean isEmpty(E[] list) { return !isNotEmpty(list); } }