Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

Java String length() Method

❮ String Methods


Example

Return the number of characters in a string:

public class MyClass {
  public static void main(String[] args) {
    String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    System.out.println(txt.length());
  }
}

Run example »


Definition and Usage

The length() method returns the length of a specified string.

Note: The length of an empty string is 0.


Syntax

public int length()

Parameters

None.

Technical Details

Returns: An int value, representing the length of the string

❮ String Methods