java.lang.StringBuffer length()

Description :

This java tutorial shows how to use the length() method of StringBuffer class under java.lang package. The length method of StringBuffer class counts how many characters does the StringBuffer object has.

Method Syntax :

public StringBuffer length()

Parameter Input :

DataType Parameter Description

Method Returns :

The length() method simply returns the length (character count).

Compatibility Version :

Requires Java 1.0 and up

Java Code Example :

This java example source code demonstrates the use of length() method of StringBuffer class. Basically this code just takes a user input and then the program will display the character length of the user input. This source code is a good example in learning on how to initialize StringBuffer object, modify the contents of the StringBuffer object and printing the length of how many characters stored on the buffer.

Sample Output :

Running the example source code above will give you the following output

Exception Scenario :

Similar Method :

  • N/A

Suggested Reading List :

References :