Wednesday, October 11, 2017

How to find out the length of the string without using length function

There are several methods.., one method is by using toCharArray() method


package com.simplePrograms;

public class Length {

    public static void main(String[] args) {
       
        String blah = "HellO";
        int count = 0;
        for (char c : blah.toCharArray()) {
            count++;
        }
        System.out.println("blah's length: " + count);
    }

}

0 comments:

Post a Comment