safe Contains Ignore Case - Java java.lang

Java examples for java.lang:String Contain

Description

safe Contains Ignore Case

Demo Code


//package com.java2s;
import java.util.Locale;

public class Main {
    public static void main(String[] argv) {
        String s = "java2s.com";
        String lookFor = "java2s.com";
        System.out.println(safeContainsIgnoreCase(s, lookFor));
    }/*from   w w w .java 2 s .co m*/

    public static boolean safeContainsIgnoreCase(final String s,
            final String lookFor) {
        if (s == null)
            return lookFor == null;
        if (lookFor == null)
            return false;
        return s.toLowerCase(Locale.UK).contains(
                lookFor.toLowerCase(Locale.UK));
    }
}

Related Tutorials