character java是什么,让我们一起了解一下?
character类用于对单个字符进行操作,Character类在对象中包装一个基本类型 char 的值,Java语言为内置数据类型char提供了包装类Character类。
character的构造方法示例代码如下:
public class characterDemo { public static void main(string[] args){ //创建对象 //Charcter ch=new Character((char)97); Character ch=new Character('a') System.out.println("ch:"+ch);
运行结果:
ch:a
几个主要方法:
public static boolean isUpperCase(char ch):判断给定的字符是否是大写字符
public static boolean isLowerCase(char ch):判断给定的字符是否是小写字符
public static boolean isDigit(char ch):判断给定的字符是否是数字字符
public static char toUpperCase(char ch):把给定的字符转换为大写字符
public static char toLowerCase(char ch):把给定的字符转换为小写字符
具体代码如下:
public class CharacterDemo { public static void main(string[] args){ //public static boolean isUpperCase(charch):判断给定的字符是否是大写字符 System.out.println("isUpperCase:"+Character.isUpperCase('A)); System.out.println("isUpperCase:"+Character.isUpperCase('a')); System.out.println("isUpperCase:"+Character.isUpperCase('e')); System.out.println("---------------- ---------"); //public static boolean isLowerCase(charch):判断给定的字符是否是小写字待 System.out.println("isLowerCase:"+Character.isLowerCase('A')); System.out.println("isLowerCase:"+Character.isLowerCase('a')); System.out.println("isLowerCase:"+Character.isLowerCase('0')); System.out.println("---------------------------------"); //public static boolean isDigit(charch):判断给定的字符是否是数字字符 System.out.println("isDigit:"+Character.isDigit('A')); System.out.println("isDigit:"+Character.isDigit("a')): System.out.println("isDigit:"+Character.isDigit("0')); System.out.println("------------------ -----------"); //public static char toUpperCase(charch)把给定的字符转换为大写字符 System.out.println("toUpperCase:"+Character.toUpperCase('A')); System.out.println("toUpperCase:"+Character.toUpperCase('a')); System.out.println("---------------------------------"); //public static char toLowerCase(char ch):把给定的字符转换为小写字符 System.out.println("tolowerCase:"+Character.toLowerCase('A)): System.out.println("toLowerCase:"+Character.toLowerCase('a')); }}
运行结果:
isUpperCase:trueisUpperCase:falseisUpperCase:false
以上就是小编今天的分享了,希望可以帮助到大家。