You are here: Home / Topics / setLength() method example in Java

setLength() method example in Java

Filed under: Java on 2023-08-23 18:57:03

// Program to explain the following StringBuffer function :
// void setLength( int len )

class  MsetLength
{
public static void main(String args[ ])
{
 StringBuffer sb1 = new StringBuffer("Java Programming Examples.");
 System.out.println(" String = " + sb1);

 sb1.setLength(12);

 System.out.println(" String = " + sb1);

 sb1.setLength(4);

 System.out.println(" String = " + sb1); 
}
}


Output:

String = Java Programming Examples.
String = Java Program
String = Java

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.