Java String length() method example

HQ » Java Tutorial » java.lang » String » length() method example
Java String length() method example 2018-02-19T12:57:09+00:00

java.lang.String length()

Description :

This java tutorial shows how to use the length() method of java.lang.String class. This method returns an int data type which is the number of Uncicode units of the String . This is generally just counts how many characters are in the String object.

Method Syntax :

public int length()

Method Returns :

This method returns an int datatype which is the character count of the String Object.

Exception :

No Exception is expected as specified on java api.

Java Code Example :

This example source code demonstrates the use of length() method of String class. Basically this example just prints the size of our string.

Sample Output :

Running the above example of length() method implementation will give you the following output

java string length method example

java string length method example

Exception Scenario :

No Exception specified on Java API

Suggested Reading List :


Contact Info


Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.