Java String Class

Source: Internet
Author: User

One, the String class

1, the string is a special object.
2. Once the string is initialized, it cannot be changed.

The String class represents a string and cannot be replicated because it has no subclasses.

Demo:

1  PackageCom.hpioneer.Demo;2 3 /**4 * @Description: String class5 * @Author: Hpioneer6 * @CreateTime: 2018/5/7 11:137 * @File: Java_string of Javaproject in Com.hpioneer.Demo8 * @FullFileName: com.hpioneer.Demo.Java_String9 * @Create by IntelliJTen * @Version: 1.0 One  */ A  Public classdemo_string{ -      Public Static voidMain (string[] args) { -  the         //character array to string -         Char[] Array = {' R ', ' U ', ' n ', ' o ', ' o ', ' B '}; -String string =NewString (Array); - System.out.println (string); +System.out.println (String.Length ());//length -System.out.println ("1, Hello,". Concat (string));//Stitching +System.out.println (", Hello," + string);//Stitching ASystem.out.printf ("The value of the floating-point variable is" + "%f, the value of the integer variable is" + "%d, the value of the string variable is" + "is%s", 1.0, 1, "1.0");//Formatting at System.out.println (); -  -String q = "a"; -String w = "B"; -String e = q +W; -String r =NewStringBuffer (). Append (q). Append (W). ToString ();//the implementation of the string addition is the append after buffer is in  -String a = "Saff"; toString B = "Saff"; +String C =NewString ("Saff"); -System.out.println (A.equals (b));//true theSystem.out.println (A.equals (c));//true *     } $ Panax Notoginseng}

Second, StringBuffer class

Demo:

1  PackageCom.hpioneer.Demo;2 3 /**4 * @Description:5 * @Author: Hpioneer6 * @CreateTime: 2018/5/7 11:587 * @File: Demo_stringbuffer of Javaproject in Com.hpioneer.Demo8 * @FullFileName: Com.hpioneer.Demo.Demo_StringBuffer9 * @Create by IntelliJTen * @Version: 1.0 One  */ A  Public classDemo_stringbuffer { -      Public Static voidMain (string[] args) { -  the        /*StringBuffer s = new StringBuffer (); - System.out.println (S.length ());//0 - System.out.println (S.capacity ());//16 Initial capacity -  + stringbuffer S1 = new StringBuffer (ten); - System.out.println (S1.length ());//0 + System.out.println (S1.capacity ());//10 A  at stringbuffer s2 = new StringBuffer ("Asas"); - System.out.println (S2.length ());//8 - System.out.println (S2.capacity ());//24 = 8+16 -  - System.out.println (S2.append (true));//asastrue - S2.deletecharat (0); in S2.delete (0,3); - System.out.println (S2.append ("DFDFDF"));//TRUEDFDFDF to System.out.println (S2.append ());//truedfdfdf100 + System.out.println (S2.insert (4, "KK"));//truekkdfdfdf100 - System.out.println (S2.reverse ());//001fdfdfdkkeurt the System.out.println (S2.replace (0,2, "111"));//1111fdfdfdkkeurt * System.out.println (s2.substring (2,5));//11f*/ $ Panax Notoginseng         /*stringbuffer sb = new StringBuffer ("Heima"); -  the string S1 = new string (SB); Convert StringBuffer to string by construction + System.out.println (S1); A  the String s2 = sb.tostring (); Convert StringBuffer to string using the ToString method + System.out.println (S2); -  $ String s3 = sb.substring (0, Sb.length ()); Converts a stringbuffer to a string by intercepting substrings $ System.out.println (S3);*/ -  -String s = "Heima"; the System.out.println (s); - Change (s);Wuyi System.out.println (s); the         //System.out.println (s+= "ITCA"); -System.out.println ("---------------------"); WuStringBuffer SB =NewStringBuffer (); -Sb.append ("Heima"); About System.out.println (SB); $ Change (SB); - System.out.println (SB); -  -          A     } +  the     Public Static voidChange (StringBuffer sb) { -Sb.append ("Itcast"); $     } the  the      Public Static voidChange (String s) { thes + = "Itcast"; the     } -      in}

Java String Class

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.