天天看点

java 判断字符串里是否包含中文字符

public static void main( String[] a ) {
        System.out.println( ifContainChinese( "你好 Earth" ) );
    }

    // java 判断字符串里是否包含中文字符
    public static boolean ifContainChinese( String str ) {
        Pattern p = Pattern.compile( "[\u4e00-\u9fa5]" );
        Matcher m = p.matcher(str);

        if ( m.find() ) {
            return true;
        }

        return false;
    }