How to detect if string contains only uppercase letter in Java
来源:https://www.programcreek.com/2011/04/a-method-to-detect-if-string-contains-1-uppercase-letter-in-java/
My approach
This method loop through each character in the string, and determine if each character is in upper case. Upper case letter value is from 97 to 122.
public static boolean testAllUpperCase(String str){ |
Any other better approach regarding the performance?
Option
From Hans Dampf's comment below:
Use java.lang.Character#isUpperCase() and #isLetter() instead of the magic numbers.
评论