by Dinesh Thakur

int length (): This method returns the number of characters currently in the invoking string buffer. For example,

str1.1ength ()

will return 10, which is the number of characters in the string literal Welcome that is referenced by strl.

public class StringLength

{
         public static void main(String[] args)
    {
            StringBuffer s1 = new StringBuffer();
            StringBuffer s2 = new StringBuffer(35);
            StringBuffer s3 = new StringBuffer("Hello Java");
            System.out.println("s1.length() =  "  + s1.length());
            System.out.println("s2.length()  = " + s2.length());
            System.out.println("s3.length() =  "  + s3.length());
           
     }
}

Stringbuffer Length() in Java Example