1. Conversion function of the String class
byte [] getBytes ()char[] ToCharArray ()static String valueOf ( Char[] CHS)static string valueOf (int i) string toLowerCase () String toUpperCase () string concat (String str)
2. Case:
1 Packagecn.itcast_05;2 3 /*4 * Conversion function of string:5 * byte[] getBytes (): converts the string to a byte array . 6 * char[] ToCharArray (): converts a string to a character array . 7 * static string ValueOf (char[] CHS): turns the character array into a string . 8 * static string valueOf (int i): turns data of type int into a string . 9 * Note: The valueof method of the string class can turn any type of data into a string. Ten * String toLowerCase (): turns the string into lowercase . One * String toUpperCase (): turns the string into uppercase . A * String concat (String str): concatenation of strings . - */ - Public classStringdemo { the Public Static voidMain (string[] args) { - //defines a String object -String s = "Javase"; - + //byte[] GetBytes (): Converts the string to a byte array. - byte[] Bys =s.getbytes (); + for(intx = 0; x < bys.length; X + +) { A System.out.println (bys[x]); at } -System.out.println ("----------------"); - - //char[] ToCharArray (): Converts a string to a character array. - Char[] CHS =S.tochararray (); - for(intx = 0; x < chs.length; X + +) { in System.out.println (chs[x]); - } toSystem.out.println ("----------------"); + - //static string ValueOf (char[] CHS): Turns the character array into a string. theString SS =string.valueof (CHS); * SYSTEM.OUT.PRINTLN (ss); $System.out.println ("----------------");Panax Notoginseng - //static string valueOf (int i): turns data of type int into a string. the inti = 100; +String SSS =string.valueof (i); A System.out.println (SSS); theSystem.out.println ("----------------"); + - //string toLowerCase (): Turns the string into lowercase. $System.out.println ("toLowerCase:" +s.tolowercase ()); $System.out.println ("s:" +s); - //System.out.println ("----------------"); - //string toUpperCase (): Turns the string into uppercase. theSystem.out.println ("toUpperCase:" +s.touppercase ()); -System.out.println ("----------------");Wuyi the //String concat (String str): Concatenation of strings. -String S1 = "Hello"; WuString s2 = "World"; -String s3 = S1 +S2; AboutString S4 =s1.concat (S2); $System.out.println ("S3:" +S3); -System.out.println ("S4:" +S4); - } -}
Operation Result:
Java Fundamentals Hardening the conversion function of the string class of the 35:string class