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