what is the wrong of the following code , i am trying to write the length method source code , i tried it with c++ ( same logic i mean ) and it worked , but here it give me the below exception error : StringIndexOutOfBoundsException , thanks for helping . Note : iam using intellij idea
package com.company;
public class Main {
public static void main(String args[]) {
String text = "hello world";
int i = 0;
while (text.charAt(i) != '\0') {
i++;
}
System.out.println(i);
}
}