Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  

String length without using length() method in java



Share on Google+Share on Google+

Naulej kumar
String length without using length() method in java
1 Answer(s)      5 years ago
Posted in : Java Beginners

How to count length of string without using length() method in java?

View Answers

June 28, 2012 at 5:54 PM

Here is Example:

package RoseIndia;

public class ArrayString {
    public static void main (String [] args){
        int i=0;
        String str = "Roseindia";
        char[] cArray = str.toCharArray();
        for (char c : cArray)

        System.out.println("String length : " + i);


String length : 9

Description: This example count the number of character into the given string without using the length() method. Store the given string str into the char array by using method toCharArray(). Now take for loop as and increment int variable i till cArray has value. Now variable i contain the length of your string


Related Tutorials/Questions & Answers: