Java String length() Method

length():

Returns the length of this string.

Syntax:

public int length()

 

Example

class TestString{
    String str = "www.w3schools.blog";

    public void stringLengthTest(){
        System.out.println(str.length());
    }
}

public class StringLengthExample {
    public static void main(String args[]){
        //creating TestString object
        TestString obj = new TestString();
        
        //method call
        obj.stringLengthTest();
    }
}

Output

20

 

Please follow and like us:
Content Protection by DMCA.com