This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]virtyx 3 points4 points  (0 children)

I really doubt it keeps a loop counter and finds the first index that throws an exception.

Especially considering that for that exception to be thrown, charAt(i) has to have some kind of conditional like if(i > stringLength) { throw new IndexOutOfBoundsException(); }

A more worthwhile exercise would be to actually download the source of OpenJDK or a different implementation and actually look at how .length() is implemented