1.建構方法:
#Character ch1 = new Character( 'A');
以char型#變數作為參數建立Character物件;
2.常用方法:
#Character類別提供了許多方法完成字元的操作:
①charValue(): 傳回值類型:char;
##功能說明:傳回Character對象的值。
②compareTo(Character anotherCharacter):傳回值類型:int
功能說明:比較兩個Character對象,若相等返回0,若呼叫對像小於anotherCharacter對象回傳負值,##
#否則回傳正值
③equals(Character anotherCharacter):傳回值類型:boolean
#功能說明:比較兩個Character對象,若相等回傳true,否則回傳false。
④toUpperCase(char ch):將字元參數轉換為大寫(要求必須有參數)
⑤toLowerCase(char ch):將字元參數轉換為小寫()
功能說明:有三種呼叫方式:
1.String str = Character.toString('A');
#2.Character ch = Character.valueOf('A');
String str = Character.toString(ch);
3.Character ch = Character.valueOf('A');
#String str = ch.toString();
⑦isUpperCase(char ch):傳回值類型:boolean
功能說明:判斷指定字元是否為大寫(要求必須有參數)
⑧isLowerCase (char ch):傳回型別:boolean
功能說明:判斷指定字元是否為小寫(要求必須有參數)
#⑨valueOf(char ch);傳回值類型:Character物件
##功能說明:傳回值為ch的Character物件。
注意:參數只能為char類型,而不能為String類型。
eg:
#
<span style="font-size: 14px;">package Number;<br/>public class IntFunction{<br/> public static void main (String []args)<br/> {<br/> Character ch1 = Character.valueOf('A');<br/> Character ch2 = new Character('A');<br/> Character ch3 = Character.valueOf('C');<br/> char c1 = ch1.charValue();<br/> char c2 = ch2.charValue();<br/> char c3 = ch3.charValue();<br/> System.out.println("ch1:" + c1 + ", ch2:" + c2 + ", ch3:" + c3);<br/> int a1 = ch1.compareTo(ch2);<br/> int a2 = ch1.compareTo(ch3);<br/> System.out.println("ch1.compareTo(ch2):" + a1 + ", ch1.compareTo(ch3):" + a2);<br/> boolean bool1 = ch1.equals(ch2);<br/> boolean bool2 = ch1.equals(ch3);<br/> System.out.println("ch1.equals(ch2): " + bool1 + ", ch1.equals(ch3): " + bool2);<br/> boolean bool3 = Character.isUpperCase(ch1);<br/> boolean bool4 = Character.isUpperCase('s');<br/> System.out.println("bool3:" + bool3 + ", bool4:" + bool4);<br/> char c4 = Character.toUpperCase('s');<br/> Character c5 = Character.toLowerCase(ch1);<br/> System.out.println("c4:" + c4 + ", c5:" + c5);<br/> } <br/>}<br/>/*运行结果:<br/>ch1:A, ch2:A, ch3:C<br/>ch1.compareTo(ch2):0, ch1.compareTo(ch3):-2<br/>ch1.equals(ch2): true, ch1.equals(ch3): false<br/>bool3:true, bool4:false<br/>c4:S, c5:a<br/>*/<br/></span>
【相關推薦】
1. Java免費視訊教學
以上是關於包裝類別Character的實例解析的詳細內容。更多資訊請關注PHP中文網其他相關文章!