Length() Method In Java

In this section, you will learn how to use length() method of the String class These method are illustration as follow here:

Description of program:

Here, we will know that how many character of length in String. First of all, we have to define class named “LengthofString”. Inside of class we have to define method of class in  main class. After that we create one method which returns the integer type values. So we are using to length() method of the String class for the purpose.

length() method : This method return the length of this string as an integer value.

Here is the the code of this program:

import java.io.*;

class LengthofString{
  public static void main(String[] args){
  try{
  BufferedReader object=
  new BufferedReader (new InputStreamReader(System.in));
  System.out.println("Eneter String:");
  String sl= object.readLine();
  int lenS = sl.length();
  System.out.println(lenS);
  }
  catch(Exception e){}
  }
}

Enjoy Code.