w3resource logo

Introduction to Java Programming

Java String: length() Method

Secondary Nav

public int length()

The length() method is used to get the length of this string. The length is equal to the number of Unicode code units in the string.

Java Platform: Java SE 8

Syntax :


Return Value : the length of the sequence of characters represented by this object.

Return Value Type: int

Example : Java String length() Method

The following example shows the usage of java String() method.

public class Example {
public static void main(String[] args)
    String str = "example.com";
    // Get the length of str.
int len = str.length();
System.out.println("The string length of '"+str+"' is: "+len);


The string length of 'example.com' is: 11

Java Code Editor :

Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program