Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
String length example 
 

In this section, you will learn how to get the length of given string.

 

String length example

                         

In this section, you will learn how to get the length of given string. The lang package of java provides the facility for getting the length of string. You will see in the following program for getting the length of string by using the length() method that returns integer type value of any given string. After running this program takes any string in command line and calculates its length.

Description of code:

length():
This is the method that returns the length of given string in integer type.

Here is the code of program:

import java.lang.*;
import java.io.*;

public class StringLength{
  public static void main(String[] argsthrows IOException{
    System.out.println("String lenght example!");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Please enter string:");
    String str = bf.readLine();
    int len = str.length();
    System.out.println("String lenght : " + len);
  }
}

Download this example.

Output of program:

C:\vinod\Math_package>javac StringLength.java

C:\vinod\Math_package>java StringLength
String lenght example!
Please enter string:
RoseIndia.net
String lenght : 13

                         

» View all related tutorials
Related Tags: c file array class list ui lists method get name using this oo root example where to exam drive store

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

Typo in the word length in println()
("String lenght example!");

Posted by Dev on Sunday, 02.3.08 @ 04:29am | #47037

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.