String Conversion Function, String Conversion

Source: Internet
Author: User

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 );}}

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.