Hacker News new | ask | show | jobs
by krrose27 5186 days ago
The thing is String.length() doesn't do any re-computation. All it does is return a variable defined in the String object that is modified when the string it contains changes.

See my other comment saying you should ignore any speed suggestions by the article.

1 comments

That is correct from the String source I am seeing. It simply returns a field, so the JVM probably inlines it into the for loop conditional making this advice not really necessary.