Hello I am writing the java program to get the Length of the String without String method.So I am using loop.
But I am getting the error as -
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 14
at StringLengthwithoutMethod.main(StringLengthwithout Method.java:17)
Here is my program -
public class StringLengthwithoutMethod {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "This is string";
int i=0;
char[] chararr = str.toCharArray();
while(chararr[i]!='\0'){
++i;
}
}
}