Naulej kumar
String length without using length() method in java
1 Answer(s)      4 years and 8 months 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: