The example will demonstrate how to get length of a StringBuffer object in Java.
Source Code
package com.beginner.examples;
public class StringBufferLength {
public static void main(String[] args) {
//Create StringBuffe.
StringBuffer stringBuffer = new StringBuffer("Hello World");
/*
* To get the length of StringBuffer use the method length() of Java StringBuffer.
*/
int result = stringBuffer.length();
System.out.println("The length of StringBuffer is :" + result);
}
}
Output:
The length of StringBuffer is :11