.length()

BrandonDusch's avatar
Published Jun 30, 2022
Contribute to Docs

The .length() method returns the number of characters contained in a string.

Syntax

string.length()

No parameters are required for the .length() method.

Example

The .length() method is showcased in the following example:

import java.io.*;
class Example {
public static void main(String[] args) {
String greetings = "Hello, Code Ninja!";
System.out.println(greetings.length());
}
}

All contributors

Contribute to Docs

Learn Java on Codecademy