Java String length() Method

 Posted On  | Yashwant Chavan 

In this tutorial you will learn how to get String length using java.

Refer below steps

  • String.length() method returns the length of this string.
  • For Unicode length is equal to the number of Unicode units in the string. Refer second example which prints length as 5.

Java String length example

package com.technicalkeeda.app;

public class StringLength {
    public static void main(String[] args) {
        String str = "technicalkeeda";
        System.out.println("World Length:- " + str.length());

        str = "\u0048\u0065\u006C\u006C\u006F";

        System.out.println("Unicode String " + str + " Length:- " + str.length());

    }
}

Output

World Length:- 14
Unicode String Hello Length:- 5


© technicalkeeda.com 2017

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0310 seconds.