Google+

155. Using 'substring( )' method with StringBuffer








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:

1. Create 'substringDemo' class under any project as shown below:
























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.




1 comment:

Aha Radio said...

It would gr8 to have details around Page Object Model with 3 page website covering different functions in 3 web page of site.

And also with exmaples around page factory concept for 3 web pages sample any site

Blog Index