Home Java Beginners length() Method In Java



length() Method In Java
Posted on: June 5, 2007 at 12:00 AM
In this section, you will learn how to use length() method of the String class.

length() Method In Java

     

In this section, you will learn how to use length() method of the String class. We are going to using length() method. 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 "StringLength". 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 StringLength{
  public static void main(String[] args){
  try{
  BufferedReader object=
 
new BufferedReader (new InputStreamReader(System.in));
  System.out.println("Eneter string value:");
  String s=object.readLine();
  int len=s.length();
  System.out.println(len);
  }
  catch(Exception e){}
  }
}

Output this program:

C:\java_work>javac StringLength.java

C:\java_work>java StringLength
Eneter string value:
amar
4
C:\java_work>

Download this program:

Related Tags for length() Method In Java:
cstringideclassintegermethodtypecharvaluenamereturnusingintidailengthcharactercreatedefineforctevaluestoposeilmainpemanfirstinnoasmnttrsidsideososafterclesallnamedmehowwhichsurnsoatanyrackirhalleaaractstrvassriringthavstaluafhatfinmanyono


More Tutorials from this section

Ask Questions?    Discuss: length() Method In Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.