Here you can find the source of contains(List
Parameter | Description |
---|---|
A | list of strings |
String | to lookup |
whether | the lookup is case sensitive or not |
public static boolean contains(List<String> list, String str, boolean bcaseSensitive)
//package com.java2s; /*/*from w w w . j a v a 2 s .c o m*/ * * Copyright (c) 2012-2015 VMware, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, without * warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the * License for the specific language governing permissions and limitations * under the License. * */ import java.util.List; public class Main { /** * @param A list of strings * @param String to lookup * @param whether the lookup is case sensitive or not * @return true or false (if there is a match in the desired case sensitive mode) */ public static boolean contains(List<String> list, String str, boolean bcaseSensitive) { if (list == null || list.isEmpty() || isNullOrEmpty(str)) return false; if (bcaseSensitive) { return list.contains(str); } for (String s : list) { if (s.equalsIgnoreCase(str)) return true; } return false; } public static boolean isNullOrEmpty(String str) { return (str == null) || (str.isEmpty()); } }