How to set length of StringBuffer using setLength method of StringBuffer class in Java. - Java Language Basics

Java examples for Language Basics:StringBuffer

Description

How to set length of StringBuffer using setLength method of StringBuffer class in Java.

Demo Code


public class Main {
       //from ww w  .j a v  a2s  .co  m
        public static void main(String[] args) {
                StringBuffer sbf = new StringBuffer("StringBuffer setLength method example");
                sbf.setLength(12);
                System.out.println("StringBuffer contents: " + sbf);
                sbf.setLength(0);
                System.out.println("StringBuffer contents deleted:" + sbf);
        }
}
 

Result


Related Tutorials