这是我第一次使用Java 的Pattern 类,因为我想检查一个字符串是否为大写。 “.”等特殊符号和“,”应被视为大写。以下是预期结果:
"test,." should return false //because it has a lowercase character
"TEST,." should return true //because all are uppercase and the special characters
"test" should return false //because it has a lowercase character
"TEST" should return true //because all are uppercase
"teST" should return false //because it has a lowercase character
我尝试使用 apache 的 StringUtils 但它不能这样工作..
最佳答案
您可以检查:
if (str.toUpperCase().equals(str)) {..}
关于java - 检查字符串中除特殊符号外的所有字符是否均为大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20145591/