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);
}
}
c++and therefore the logic does not make any sense in java. hg.openjdk.java.net/jdk7u/jdk7u6/jdk/file/8c2c5d63a17e/src/…length()on your Strings to get their length.\0in a javaString(unless you explicitly put a \0 in a String, which is perfectly valid)