Returns true if a string contains any upper case characters. - Android java.lang

Android examples for java.lang:String Search

Description

Returns true if a string contains any upper case characters.

Demo Code

import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Locale;

public class Main{

    /**//from  ww  w .ja  va 2s  . c o  m
     * Returns true if cs contains any upper case characters.
     *
     * @param cs the CharSequence to check
     * @return {@code true} if cs contains any upper case characters, {@code false} otherwise.
     */
    public static boolean hasUpperCase(final CharSequence cs) {
        final int length = cs.length();
        for (int i = 0, cp = 0; i < length; i += Character.charCount(cp)) {
            cp = Character.codePointAt(cs, i);
            if (Character.isUpperCase(cp)) {
                return true;
            }
        }
        return false;
    }

}

Related Tutorials