Java Fundamentals Strengthen the interception function of the stringbuffer of 43:stringbuffer class

Source: Internet
Author: User

1. StringBuffer's interception function:

Public String subString (int Start):

Public String subString (int Start, int end):

The return type is of type string, which is different from the previous functions and does not change itself.

2. Case Demo:

1  Packagecn.itcast_06;2 3 /*4 * stringbuffer interception function: Note that the return value type is no longer the stringbuffer itself. 5 * Public String substring (int start)6 * Public String substring (int start,int end)7  */8  Public classStringbufferdemo {9      Public Static voidMain (string[] args) {Ten         //creating a String buffer object OneStringBuffer SB =NewStringBuffer (); A  -         //adding elements -Sb.append ("Hello"). Append ("World"). Append ("Java"); theSystem.out.println ("SB:" +SB); -  -         //interception function -         //Public String substring (int start) +String s = sb.substring (5); -System.out.println ("s:" +s); +System.out.println ("SB:" +SB); A  at         //Public String substring (int start,int end) -String SS = sb.substring (5, 10); -SYSTEM.OUT.PRINTLN ("SS:" +ss); -System.out.println ("SB:" +SB); -     } -}

The results of the operation are as follows:

Java Fundamentals Strengthen the interception function of the stringbuffer of 43:stringbuffer 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.