how to get length of a StringBuffer object - Java Language Basics

Java examples for Language Basics:StringBuffer

Introduction

int length() method of Java StringBuffer class returns the length of a StringBuffer object.

Demo Code

 
public class Main {
 
  public static void main(String[] args) {
   /*  ww w.j  a v a2  s.co  m*/
    StringBuffer sb = new StringBuffer("Hello World");
    int len = sb.length();
    System.out.println("Length of a StringBuffer object is : " + len);
  }
}

Result


Related Tutorials