Java List Contain contains(List list, String str, boolean bcaseSensitive)

Here you can find the source of contains(List list, String str, boolean bcaseSensitive)

Description

contains

License

Open Source License

Parameter

Parameter Description
A list of strings
String to lookup
whether the lookup is case sensitive or not

Return

true or false (if there is a match in the desired case sensitive mode)

Declaration

public static boolean contains(List<String> list, String str, boolean bcaseSensitive) 

Method Source Code

//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());
    }
}

Related

  1. contains(List list, Object element, int begin, int end)
  2. contains(List objects, Object object)
  3. contains(List listOfArrays, A[] array)
  4. contains(List list, int[] arr)
  5. contains(List list, List> listOfLists)
  6. contains(List list, String string)
  7. contains(List list1, List list2)
  8. contains(List container, List list, Comparator comparator)
  9. contains(String str, List list)