Use of APIs in java.lang.String

Source: Internet
Author: User

1 /**2 * java.lang.String:3 * Copy the string contents into the byte array;4 * String Connection: One string is appended to another string;5 * Replace: Character substitution, string substitution;6 * match and replace;7 * Multiple types of data are converted into string types;8 * Conversion of strings to character arrays;9 * Determine if a string is included;Ten * byte array and string conversion; One  */ A  PackageLang; -  - Importjava.util.Arrays; the  -  Public classStringdemo - { -      Public Static voidMain (string[] args) +     { -String str = "ASDFGHJ"; +         Char[] ch =New Char[Str.length ()]; A         //Copy the string contents into a byte array atStr.getchars (0, Str.length (), CH, 0); - System.out.println (arrays.tostring (CH)); -          -String str2 =NewString ("123456"); -         //put the string str2 behind the string str - Str2.concat (str); in System.out.println (str2); -          toString STR3 = "123123123"; +         //character substitution, followed by the character replacing the preceding character; -         //returns a new string with the previous string content unchanged theString STR4 = Str3.replace (' 3 ', ' 4 '); *         //print out the result is the same $ System.out.println (STR3);Panax Notoginseng         //The result is 124124124 . - System.out.println (STR4); the         //string Substitution: The following string is replaced with the preceding string +String str8 = Str3.replace ("123", "456"); A         //The result is 456456456 . the System.out.println (str8); +          -String STR9 = "a123b456c789"; $         //match and replace: match to meet the requirements, then replace $String str10 = Str9.replaceall ("[A-Z]", "D"); -         //The result is d123d456d789 . - System.out.println (STR10); the         //match to the first one and replace it, whichever is later matched -String Str11 = Str9.replacefirst ("[A-Z]", "D");Wuyi System.out.println (STR11); the          -         DoubleD = 12.54; Wu         //double type to string -         //There are multiple overloaded methods AboutString STR5 =string.valueof (d); $ System.out.println (STR5); -         //equivalence: As with the above results -String STR6 =double.tostring (d); - System.out.println (STR6); A          +         Char[] C2 = {' A ', ' s ', ' d ', ' F '}; the         //character array into a string -         //there are overloaded methods $String STR7 =string.valueof (C2); the System.out.println (STR7); the          the         //string to character array the         Char[] C3 =Str7.tochararray (); - System.out.println (Arrays.tostring (C3)); in          theString str12 = "123"; the System.out.println (); About         //can only be judged if it contains a string and cannot be judged to contain characters theSystem.out.println (Str12.contains ("12")); the          theString Str13 = "Uhbijn"; +         //string to byte array -         byte[] B =str13.getbytes (); the         //arrays.tostring (): Multiple overloaded methods that can print multiple types of arraysBayi System.out.println (arrays.tostring (b)); the          the         //byte array goto string -String Str14 =NewString (b); - System.out.println (str14); the     } the}

Use of APIs in java.lang.String

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.