Java StringBuffer setLength() method - Sets the length of the character sequence.
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
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course