常見物件-Character

ZHOU_VIP發表於2017-05-20

package cn.itcast_01;

/*
 * Character 類在物件中包裝一個基本型別 char 的值
 * 此外,該類提供了幾種方法,以確定字元的類別(小寫字母,數字,等等),並將字元從大寫轉換成小寫,反之亦然
 * 
 * 構造方法:
 * 		Character(char value)
 */
public class CharacterDemo {
	public static void main(String[] args) {
		// 建立物件
		// Character ch = new Character((char) 97);//97,int轉成char
		Character ch = new Character('a');
		System.out.println("ch:" + ch); //a
	}
}

Character的常見方法講解:


package cn.itcast_02;

/*
 * 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(char ch):判斷給定的字元是否是大寫字元
		System.out.println("isUpperCase:" + Character.isUpperCase('A')); //true
		System.out.println("isUpperCase:" + Character.isUpperCase('a')); //false
		System.out.println("isUpperCase:" + Character.isUpperCase('0')); //false

		// public static boolean isLowerCase(char ch):判斷給定的字元是否是小寫字元
		System.out.println("isLowerCase:" + Character.isLowerCase('A'));
		System.out.println("isLowerCase:" + Character.isLowerCase('a'));
		System.out.println("isLowerCase:" + Character.isLowerCase('0'));

		// public static boolean isDigit(char ch):判斷給定的字元是否是數字字元
		System.out.println("isDigit:" + Character.isDigit('A'));
		System.out.println("isDigit:" + Character.isDigit('a'));
		System.out.println("isDigit:" + Character.isDigit('0'));

		// public static char toUpperCase(char ch):把給定的字元轉換為大寫字元
		System.out.println("toUpperCase:" + Character.toUpperCase('A'));
		System.out.println("toUpperCase:" + Character.toUpperCase('a'));

		// public static char toLowerCase(char ch):把給定的字元轉換為小寫字元
		System.out.println("toLowerCase:" + Character.toLowerCase('A'));
		System.out.println("toLowerCase:" + Character.toLowerCase('a'));
		
	}
}


相關文章