Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.regex.Pattern;

public class Main {
    /**
     * Check whether the target string contains the indicated sub string, and case insensitive
     * 
     * @param target  the target string
     * @param subStr  the sub string
     * @return the check result
     */
    public static boolean containsIgnoreCase(String target, String subStr) {
        target = deNull(target);
        subStr = deNull(subStr);

        return Pattern.compile(Pattern.quote(subStr), Pattern.CASE_INSENSITIVE).matcher(target).find();
    }

    /**
     * Convert a (possible) null string to "" if necessary
     * 
     * @param str a (possible) null string
     * @return "" if the string is null, or no change
     */
    public static String deNull(String str) {
        return str == null ? "" : str;
    }
}