StringBuffer length() in Java

length(): This method is available in java.lang.StringBuffer class of Java.

Syntax:

int java.lang.StringBuffer.length()

This method returns the length of this character sequence. The length is the number of 16-bit chars in the sequence.

Parameters: NA

Returns: The number of chars in this sequence.

For Example:

StringBuffer str = new StringBuffer("Hello World")

str.length() = > It returns 11.

Approach

Java

public class Length {
    public static void main(String[] args) {

        StringBuffer str = new StringBuffer("Hello World");

        System.out.println(str.length());

    }
}

Output:

11

No comments:

Post a Comment