String length java

Hey guys!! Welcome to flower brackets blog. Here in this post we are going to learn string length java.

string length java

Representation

length() method returns the length of string. The length is equal to the number of unicode code units in the string.

To find out the 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.

Java string length() method

public class StringLength
{
   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 : 14
string length : 10

Related Posts