Java Character类

Character类用于对单个字符进行操作。

Character类在对象中包装一个基本类型char的值。

在实际开发过程中,我们经常会遇到需要使用对象,而不是内置数据类型的情况,为了解决这个问题,Java语言为内置数据类型char提供了包装类Character类。

构造函数

Character(char varlue)
构造一个新分配的 Character 对象,用以表示指定的 char 值。

方法

SN 方法 & 描述
1 static int charCount(int codePoint) 
此方法确定表示指定字符所需的字符的值的数目(Unicode代码点)。
2 char charValue() 
此方法返回字符对象的值。
3 static int codePointAt(char[] a, int index) 
此方法返回char数组的给定索引上的代码点。
4 static int codePointAt(char[] a, int index, int limit) 
此方法返回的字符数组,只能用于数组元素与指数低于上限的定索引上的代码点。
5 static int codePointAt(CharSequence seq, int index) 
此方法返回CharSequence给定索引上的代码点。
6 static int codePointBefore(char[] a, int index) 
此方法返回char数组的给定索引前面的代码点。
7 static int codePointBefore(char[] a, int index, int start) 
此方法返回字符数组,其中仅可用于数组元素与指数大于或等于开始的给定索引前面的代码点。
8 static int codePointBefore(CharSequence seq, int index) 
此方法返回CharSequence给定索引前面的代码点。
9 static int codePointCount(char[] a, int offset, int count) 
该方法在char数组参数的一个子返回的Unicode代码点的数量
10 static int codePointCount(CharSequence seq, int beginIndex, int endIndex) 
该方法在指定的字符序列的文本范围返回的Unicode代码点的数量。
11 int compareTo(Character anotherCharacter) 
该方法在数字上比较两个字符的对象。
12 static int digit(char ch, int radix) 
此方法返回指定基数字符ch的数值。
13 static int digit(int codePoint, int radix) 
此方法返回指定基数指定字符(Unicode代码点)的数值。
14 boolean equals(Object obj) 
该方法此对象与指定对象比较
15 static char forDigit(int digit, int radix) 
此方法确定的指定基数的特定数字的字符表示。
16 static byte getDirectionality(char ch) 
此方法返回给定字符的Unicode的方向属性。
17 static byte getDirectionality(int codePoint) 
该方法返回给定字符(Unicode代码点)的Unicode方向属性。
18 static int getNumericValue(char ch) 
此方法返回指定的Unicode字符表示的int值。
19 static int getNumericValue(int codePoint) 
此方法返回int值指定的字符(Unicode代码点)表示。
20 static int getType(char ch) 
此方法返回一个值,表明一个字符的普通类。
21 static int getType(int codePoint) 
此方法返回一个值,表明一个字符的普通类。
22 int hashCode() 
此方法返回这个字符的哈希码。
23 static boolean isDefined(char ch) 
此方法确定字符是否为Unicode定义。
24 static boolean isDefined(int codePoint)
该方法确定的字符(Unicode代码点)在Unicode中定义。
25 static boolean isDigit(char ch) 
此方法确定指定字符是否一个数字。
26 static boolean isDigit(int codePoint) 
此方法确定指定字符(Unicode代码点)是其中一位。
27 static boolean isHighSurrogate(char ch) 
该方法判断给定char值是高代理项代码单元(也称为主导代理项代码单元)。
28 static boolean isIdentifierIgnorable(char ch) 
此方法确定指定字符是否应该被视为一个可忽略的字符在Java标识符或Unicode标识符。
29 static boolean isIdentifierIgnorable(int codePoint) 
此方法确定指定字符(Unicode代码点)应被视为一个可忽略的字符在Java标识符或Unicode标识符。
30 static boolean isISOControl(char ch) 
此方法确定指定字符是否ISO控制字符。
31 static boolean isISOControl(int codePoint) 
此方法确定引用的字符(Unicode代码点)是一家通过ISO控制字符。
32 static boolean isJavaIdentifierPart(char ch) 
该方法确定指定的字符可能是Java标识符中除首字符以外的部分。
33 static boolean isJavaIdentifierPart(int codePoint) 
该方法确定的字符(Unicode代码点)可能是Java标识符中除首字符以外的部分。
34 static boolean isJavaIdentifierStart(char ch) 
此方法确定指定字符是否允许在Java标识符的第一个字符。
35 static boolean isJavaIdentifierStart(int codePoint) 
该方法确定的字符(Unicode代码点)是否允许在Java标识符的第一个字符。
36 static boolean isLetter(char ch) 
此方法确定指定字符是否一个字母。
37 static boolean isLetter(int codePoint) 
此方法确定指定字符(Unicode代码点)是一个字母。
38 static boolean isLetterOrDigit(char ch) 
此方法确定指定字符是字母或数字。
39 static boolean isLetterOrDigit(int codePoint) 
此方法确定指定字符(Unicode代码点)是一个字母或数字。
40 static boolean isLowerCase(char ch) 
此方法确定指定字符是否为小写字母。
41 static boolean isLowerCase(int codePoint) 
此方法确定指定字符(Unicode代码点)是否为小写字母。
42 static boolean isLowSurrogate(char ch) 
该方法判断给定char值是低代理项代码单元(也称为尾部代理项代码单元)。
43 static boolean isMirrored(char ch) 
此方法确定按照Unicode规范的字符是否为镜像。
44 static boolean isMirrored(int codePoint) 
此方法确定指定字符(Unicode代码点)是否按照Unicode规范镜像。
45 static boolean isSpaceChar(char ch) 
此方法确定指定字符是否为Unicode空白字符。
46 static boolean isSpaceChar(int codePoint) 
此方法确定指定字符(Unicode代码点)是一个Unicode空格字符。
47 static boolean isSupplementaryCodePoint(int codePoint) 
此方法确定指定字符(Unicode代码点)是否在补充字符范围。
48 static boolean isSurrogatePair(char high, char low) 
此方法确定指定对char值是否一个有效的代理对。
49 static boolean isTitleCase(char ch) 
此方法确定指定字符是否是首字母大写字符。
50 static boolean isTitleCase(int codePoint) 
此方法确定指定字符(Unicode代码点)是一个首字母大写字符。
51 static boolean isUnicodeIdentifierPart(char ch) 
此方法确定指定字符可以是Unicode标识符中除首字符以外的部分。
52 static boolean isUnicodeIdentifierPart(int codePoint) 
此方法确定指定字符(Unicode代码点)可能是Unicode标识符中除首字符以外的部分。
53 static boolean isUnicodeIdentifierStart(char ch) 
此方法确定指定字符是否是允许作为Unicode标识符的第一个字符。
54 static boolean isUnicodeIdentifierStart(int codePoint) 
此方法确定指定字符(Unicode代码点)是允许作为Unicode标识符的第一个字符。
55 static boolean isUpperCase(char ch )
此方法确定指定字符是否是大写字符。
56 static boolean isUpperCase(int codePoint) 
此方法确定指定字符(Unicode代码点)是一个大写字母。
57 static boolean isValidCodePoint(int codePoint) 
此方法确定指定的代码点是否为0x0000?0x10FFFF之间包容的范围内有效的Unicode代码点值。
58 static boolean isWhitespace(char ch) 
此方法确定指定字符是否是根据Java的空白符。
59 static boolean isWhitespace(int codePoint) 
此方法确定指定字符(Unicode代码点)是根据Java的空白符。
60 static int offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset) 
此方法返回从给定指数codePointOffset码点的偏移给定的字符子数组中的索引
61 static int offsetByCodePoints(CharSequence seq, int index, int codePointOffset) 
此方法返回给定字符序列从给定的指数codePointOffset码点偏移中的索引。
62 static char reverseBytes(char ch) 
此方法返回通过反转指定char值的字节的顺序而获得的值。
63 static char[] toChars(int codePoint) 
该方法将指定字符(Unicode代码点)到其存储在一个字符数组的UTF-16表示形式。
64 static int toChars(int codePoint, char[] dst, int dstIndex) 
该方法将指定字符(Unicode代码点)其UTF-16表示形式。
65 static int toCodePoint(char high, char low) 
该方法指定的代理对到其增补代码点值转换。
66 static char toLowerCase(char ch) 
该方法的参数字符使用来自UnicodeData文件的大小写映射信息转换成小写。
67 static int toLowerCase(int codePoint) 
此方法转换的字符(Unicode代码点)参数使用来自UnicodeData文件的大小写映射信息为小写。
68 String toString() 
该方法返回一个代表该字符的值的String对象。
69 static String toString(char c) 
此方法返回一个表示指定字符的String对象。
70 static char toTitleCase(char ch) 
该方法的参数字符使用来自UnicodeData文件的大小写映射信息标题字符转换。
71 static int toTitleCase(int codePoint) 
此方法转换的字符(Unicode代码点)参数使用来自UnicodeData文件的大小写映射信息标题字符。
72 static char toUpperCase(char ch) 
该方法的参数字符使用来自UnicodeData文件的大小写映射信息转换为大写。
73 static int toUpperCase(int codePoint) 
此方法转换的字符(Unicode代码点)参数使用来自UnicodeData文件的大小写映射信息为大写。
74 static Character valueOf(char c) 
此方法返回一个表示指定字符值的字符实例。

转义序列

前面有反斜杠(\)的字符代表转义字符,它对编译器来说是有特殊含义的。

转义序列 描述
\t 在文中该处插入一个tab键
\b 在文中该处插入一个后退键
\n 在文中该处换行
\r 在文中该处插入回车
\f 在文中该处插入换页符
\' 在文中该处插入单引号
\" 在文中该处插入双引号
\\ 在文中该处插入反斜杠

例子

public class CharacterDemo02 {
    public static void main(String[] args) {
        // public static boolean isUpperCase(char ch):判断给定的字符是否是大写字符
        System.out.println("isUpperCase:" + Character.isUpperCase('A')); //isUpperCase:true
        System.out.println("isUpperCase:" + Character.isUpperCase('a')); //isUpperCase:false
        System.out.println("isUpperCase:" + Character.isUpperCase('0')); //isUpperCase:false
        System.out.println("-----------------------------------------");
        // public static boolean isLowerCase(char ch):判断给定的字符是否是小写字符
        System.out.println("isLowerCase:" + Character.isLowerCase('A')); //isLowerCase:false
        System.out.println("isLowerCase:" + Character.isLowerCase('a')); //isLowerCase:true
        System.out.println("isLowerCase:" + Character.isLowerCase('0')); //isLowerCase:false
        System.out.println("-----------------------------------------");
        // public static boolean isDigit(char ch):判断给定的字符是否是数字字符
        System.out.println("isDigit:" + Character.isDigit('A')); //isDigit:false
        System.out.println("isDigit:" + Character.isDigit('a')); //isDigit:false
        System.out.println("isDigit:" + Character.isDigit('0')); //isDigit:true
        System.out.println("-----------------------------------------");
        // public static char toUpperCase(char ch):把给定的字符转换为大写字符
        System.out.println("toUpperCase:" + Character.toUpperCase('A')); //toUpperCase:A
        System.out.println("toUpperCase:" + Character.toUpperCase('a')); //toUpperCase:A
        System.out.println("-----------------------------------------");
        // public static char toLowerCase(char ch):把给定的字符转换为小写字符
        System.out.println("toLowerCase:" + Character.toLowerCase('A')); //toLowerCase:a
        System.out.println("toLowerCase:" + Character.toLowerCase('a')); //toLowerCase:a
    }
}

版权声明:本文为JAVASCHOOL原创文章,未经本站允许不得转载。