How to find length of a String in Java

 How to find length of a String in Java







PROGRAM:


public class StringLength {

    public static void main(String args[])
    {
        String s1="hi";
        String s2="hello";
        String s3="Welcome";
        System.out.println(s1+" Length is "+s1.length());//2
        System.out.println(s2+" Length is "+s2.length());//5
        System.out.println(s3+" Length is "+s3.length());//7
    }
   
}


/*

hi Length is 2
hello Length is 5
Welcome Length is 7

*/

Comments

Popular posts from this blog

PROGRAM TO FIND FACTORIAL OF A NUMBER USING RECURSION

PROGRAM TO FIND THE COUNT OF PARTICULAR NUMBER IN AN ARRAY

TELEPHONE BOOK USING HASHMAP