JAVA program for StringBuffer method length()
This JAVA program is to find length of a string using StringBuffer method length().
StringBuffer method length() returns an integer value equal to length of the String.
For example string str=”code” then str.length() =4.
Program
import java.util.*; class sb1 { public static void main(String args[]) { String str; Scanner sc = new Scanner(System.in); System.out.println("Enter the string"); str = sc.nextLine(); StringBuffer s = new StringBuffer(str); System.out.println("Length of string = "+s.length()); } }