Java StringBuffer setLength() Example

Java StringBuffer setLength() method - Sets the length of the character sequence.

Java StringBuffer setLength() Example

Example: Example to reset the length of the StringBuffer using setLength() method.
public class SetLengthExample {
    public static void main(String[] args) {
        StringBuffer buffer = new StringBuffer("javaguides");
        System.out.println("Before set length to 0 : " + buffer.length());
        buffer.setLength(0);
        System.out.println("After set length to 0 : " + buffer.length());
    }
}
Output:
Before set length to 0 : 10
After set length to 0 : 0

Reference




Comments