String length() method in java

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

string length() method in java

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

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


string length : 14
string length : 10

Related Posts