+length(): return type int

You can get length of a string by invoking its length() method.

import java.lang.String;
class length{
                    public static void main(String[] arg){ 
                          String str="Welcome to Java";
                          System.out.println("Length: "+str.length());
                         }
                     }

Output:  Length: 15
   
Note that length is a method in the String class but is a property in an array object. Do you have to use str.length() to get the number of characters in string str and a.length to get the number of elements in array a.

Popular posts from this blog

Shutdown Pc

Ellipse using OpenGl

String Comparisons