String length() method in java

Here in this post we are going to learn string length() method in java.

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

Also read – String toUpperCase() method 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

Related Posts