java String

String length() in java Code With Examples

Table of Contents

Program

public class StringIntLength
{
     public static void main(String args[])
   {
      String abc1 = new String("My profile is on LinkedIn.com");
      String abc2 = new String("LinkedIn" );
      System.out.print("String Length :" );
      System.out.println(abc1.length());
      System.out.print("String Length :" );
      System.out.println(abc2.length());
   }
}

Output

String Length: 29
String Length: 8

Description

public int length()

Returns the length of this string. The length is equal to the number of Unicode code units in the string.

Specified by:

length in interface CharSequence

Returns:

the length of the sequence of characters represented by this object.