.length()
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());}}
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Java on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Java
Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.Beginner Friendly17 hours