java中Character.isTitleCase()
用于判断指定字符是否为标题首字符。
语法
public static boolean isTitleCase(char ch) //判断指定的字符是不是标题首字符
public static boolean isTitleCase(int codePoint) //判断指定的字符(Unicode码)是否为标题基字符
参数
- ch:要测试的字符
- codePoint:要测试的字符的Unicode码
返回值
如果字符是标题,返回true;否则返回false
源码
public static boolean isTitleCase(char ch) {
return isTitleCase((int)ch);
}
public static boolean isTitleCase(int codePoint) {
return getType(codePoint) == Character.TITLECASE_LETTER;
}
实例
public class CharacterisTitleCaseDemo {
public static void main(String[] args) {
String str="www.yxjc123.com";
char[] buffer = str.toCharArray();
for (int i = 0; i < buffer.length; i++) {
char ch = buffer[i];
if (Character.isUpperCase(ch)) {
buffer[i] = Character.toLowerCase(ch);
} else if (Character.isTitleCase(ch)) {
buffer[i] = Character.toLowerCase(ch);
} else if (Character.isLowerCase(ch)) {
buffer[i] = Character.toUpperCase(ch);
}
}
String str2 = new String(buffer);
System.out.println(str2);
}
}