length method in java
public class LengthMethodDemo {
public static void main(String[] args) {
//declaring variables string1 & string2
String string1 = "Java";
String string2 = "Java Code";
// Java
//count from left 1234 --> so length would be 4
int lengthOfString1 = string1.length(); // 4
// Java Code
//count from left 123456789 --> so length would be 9
int lengthOfString2 = string2.length(); // 9
System.out.println("Length of String1 is : "+lengthOfString1);
System.out.println("Length of String2 is : "+lengthOfString2);
String string3="";
System.out.println(string3.length()); //0
String string4=null;
System.out.println(string4.length()); //It will give NullPointerException
}
}