length( ) method when used with StringBuffer gives the current length of the StringBuffer's object.
StringBuffer object = new StringBuffer("abcdef");
object.length( ); -> Gives the length of the object it is holding now (i.e. the length of "abcdef" text in this example -> i.e. 6 )
Lets implement this on Eclipse IDE:
1. Create 'lengthDemo' class under any project as shown below:
3. Observe that the output is displayed in the console as shown below:
Click here to download this 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 'charAt( )' method with StringBuffer will be explained in the next post.