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.


public int length()


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());


string length() method in java