Check if Collection contains String Ignore Case - Android java.util

Android examples for java.util:Collection Contains

Description

Check if Collection contains String Ignore Case

Demo Code


//package com.book2s;

import java.util.Collection;

public class Main {
    public static void main(String[] argv) {
        Collection strings = java.util.Arrays.asList("asdf", "book2s.com");
        String string = "book2s.com";
        System.out.println(containsStringIgnoreCase(strings, string));
    }//from  w ww  .j a va  2  s . co m

    public static boolean containsStringIgnoreCase(
            Collection<? extends String> strings, String string) {
        if (strings == null) {
            throw new NullPointerException("strings == null");
        }

        if (string == null) {
            throw new NullPointerException("string == null");
        }

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

        return false;
    }
}

Related Tutorials