String Conversion Function, String Conversion
/** String Conversion Function: * byte [] getBytes (): converts a String to a byte array. * Char [] toCharArray (): converts a string to a character array. * Static String valueOf (char [] chs): converts a character array to a String. * Static String valueOf (int I): converts int data to a String. * Note: the valueOf method of the String class can convert any type of data to a String. * String toLowerCase (): converts a String to lowercase. * String toUpperCase (): converts a String to uppercase. * String concat (String str): concatenates a String. */Public class StringDemo {public static void main (String [] args) {// define a String object String s = "JavaSE"; // byte [] getBytes (): converts a string to a byte array. Byte [] bys = s. getBytes (); for (int x = 0; x <bys. length; x ++) {System. out. println (bys [x]);} System. out. println ("----------------"); // char [] toCharArray (): converts a string to a character array. Char [] chs = s. toCharArray (); for (int x = 0; x <chs. length; x ++) {System. out. println (chs [x]);} System. out. println ("----------------"); // static String valueOf (char [] chs): Convert the character array to a String. String ss = String. valueOf (chs); System. out. println (ss); System. out. println ("----------------"); // static String valueOf (int I): converts int data to a String. Int I = 100; String sss = String. valueOf (I); System. out. println (sss); System. out. println ("----------------"); // String toLowerCase (): converts the String to lowercase. System. out. println ("toLowerCase:" + s. toLowerCase (); System. out. println ("s:" + s); // System. out. println ("----------------"); // String toUpperCase (): converts a String to uppercase. System. out. println ("toUpperCase:" + s. toUpperCase (); System. out. println ("----------------"); // String concat (String str): concatenates strings. String s1 = "hello"; String s2 = "world"; String s3 = s1 + s2; String s4 = s1.concat (s2); System. out. println ("s3:" + s3); System. out. println ("s4:" + s4 );}}