StringBuilder length() in Java

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

Syntax:

int java.lang.AbstractStringBuilder.length()

This method returns the length (character count).

Returns: the length of the sequence of characters currently represented by this object.

Parameters: NA

Exceptions: NA

For Example:

StringBuilder str = new StringBuilder("Hello World")

str.length() = > It returns 11.

Approach

Java

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

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

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

    }
}

Output:

11

No comments:

Post a Comment