1public class Sample_String {
2 public static void main(String[] args) {
3 //declare the String as an object S1 S2
4 String S1 = "Hello Java String Method";
5 String S2 = "RockStar";
6
7 //length() method of String returns the length of a String S1.
8 int length = S1.length();
9 System.out.println("Length of a String is: " + length);
10 //8 Length of a String RockStar
11 System.out.println("Length of a String is: " + S2.length());
12 }
13}
14
1String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2System.out.println("The length of the txt string is: " + txt.length());
3