Java Fundamentals Hardening the conversion function of the string class of the 35:string class

Source: Internet
Author: User

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

Related Article

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.