String length() method in java

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

String length() method in java

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

String length() method is specified by CharSequence interface. The length is equal to the number of Unicode code units in the string.


public int length()

Let’s see String length() method example.

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

Also read – Factorial program in java