Java Collection Contain containsIgnoreCase(Collection c, String s)

Here you can find the source of containsIgnoreCase(Collection c, String s)

Description

contains Ignore Case

License

Apache License

Declaration

public static boolean containsIgnoreCase(Collection<String> c, String s) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Collection;

public class Main {
    public static boolean containsIgnoreCase(String[] strArray, String searchStr) {
        return indexOfIgnoreCase(strArray, searchStr) >= 0;
    }/*from ww  w .  ja v a2  s .  c  o m*/

    public static boolean containsIgnoreCase(Collection<String> c, String s) {
        if (c == null || s == null) {
            return false;
        }

        for (String string : c) {
            if (string.equalsIgnoreCase(s)) {
                return true;
            }
        }

        return false;
    }

    public static int indexOfIgnoreCase(String[] strArray, String searchStr) {
        return indexOfString(strArray, searchStr, true);
    }

    private static int indexOfString(String[] strArray, String searchStr, boolean ignoreCase) {
        if ((strArray == null) || (strArray.length == 0))
            return -1;

        boolean found = false;
        for (int i = 0; i < strArray.length; i++) {
            if (strArray[i] == null) {
                if (searchStr == null)
                    found = true;
            } else {
                if (ignoreCase)
                    found = strArray[i].equalsIgnoreCase(searchStr);
                else
                    found = strArray[i].equals(searchStr);
            }
            if (found)
                return i;
        }
        return -1;
    }

    public static boolean equals(byte[] data1, byte[] data2) {
        if (data1 == data2)
            return true;
        if (data1 == null || data2 == null)
            return false;
        if (data1.length != data2.length)
            return false;
        for (int i = 0; i < data1.length; i++) {
            if (data1[i] != data2[i])
                return false;
        }
        return true;
    }

    public static boolean equals(String s0, String s1) {
        boolean s0Null = s0 == null;
        boolean s1Null = s1 == null;
        if (s0Null || s1Null) {
            return s0Null == s1Null;
        }
        return s0.equals(s1);
    }
}

Related

  1. containsByIdentity(Collection collection, Object toBeFound)
  2. containsClassOrSuper(Collection classNames, String className)
  3. containsElement(Collection collect, T elem)
  4. containsIdentity(Collection collection, T element)
  5. containsIdentity(Collection objects, Object object)
  6. containsIgnoreCase(Collection c, String s)
  7. containsIgnoreCase(Collection c, String str)
  8. containsIgnoreCase(Collection collection, String testString)
  9. containsIgnoreCase(Collection collection, String value)