String length() method in java

Let’s learn string length() method in java.

String length() method in java

Java String length() method returns length of string. The length of the sequence of characters represented by this object.

Also read – this keyword in java

To find length of the string in java we have length() method which is specified by CharSequence interface.

Syntax

public int length()

Returns

returns length of characters.

public class StringLengthJava
{
   public static void main(String[] args)
   {
      String str1 = "flowerbrackets"; 
      String str2 = "helloworld"; 
      System.out.println("string length : " + str1.length()); 
      System.out.println("string length : " + str2.length());
   }
}



Output:

string length() method in java