To check if a string contains an uppercase character in Java, call
Character.isUpperCase
on every character of the string.Make a for
loop over the length()
of the string. In the loop return true
once Character.isUpperCase
returns true
:
public boolean containsUpperCaseCharacter(String string) {
for (int i = 0; i < string.length(); i++) {
if (Character.isUpperCase(string.charAt(i))) {
return true;
}
}
return false;
}