Character类将原始类型char的值包装在对象中。字符类的对象包含一个类型为char的单个字段。
以下是Character类的一些方法-
修饰符和类型 | 方法和说明 |
---|---|
static int | charCount(int codePoint) 确定表示指定字符所需的char值的数量 |
char | charValue() 返回此Character对象的值。 |
static int. | codePointAt(char [] a,int index) 返回char数组给定索引处的代码点。 |
static int | codePointAt(char [] a,int index,int limit) 返回char数组给定索引处的代码点,其中只能使用索引小于limit的数组元素。 |
static int | codePointAt(CharSequence seq,int index) 返回CharSequence给定索引处的代码点。 |
static int | codePointBefore(char [] a,int index) 返回位于char数组给定索引之前的代码点。 |
让我们看一个例子-
import java.lang.*; public class Demo { public static void main(String[] args){ System.out.println(Character.isLetter('0')); System.out.println(Character.isLetter('h')); System.out.println(Character.isLetter('K')); } }
输出结果
这将产生以下输出-
false true true
现在让我们来看另一个示例-
import java.lang.*; public class Demo { public static void main(String[] args){ System.out.println(Character.isLetter('0')); System.out.println(Character.isLetter('h')); System.out.println(Character.isLetter('K')); System.out.println(Character.toString('0')); System.out.println(Character.toString('H')); } }
输出结果
这将产生以下输出-
false true true 0 H