substring( ) method when used with StringBuffer extracts a portion from the provided string using the following two formats:
Example: (Format 1)
StringBuffer object1 = new StringBuffer("SunShine");
object1.substring(3); -> This will extract the text in "SunShine" from index 3 till the end i.e. It will extract "Shine" in this example.
Example: (Format 2)
StringBuffer object2 = new StringBuffer("SuperSunShine");
object1.substring(5,8); -> This will extract the text in "SuperSunShine" from index 3 till index (8-1) i.e. It will extract "Sun" in this example.
Lets implement this on Eclipse IDE:
2. Save and Run the 'substringDemo' class file
3. Observe that the output is displayed in the console as shown below:
Download this project:
Click here to download the project containing the class file used in this post (You can download this project and import into Eclipse IDE on your machine)
Please comment below to feedback or ask questions.
Using 'indexOf( )' method with StringBuffer will be explained in the next post.