4 ms·
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 co
by krrose27 14y 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.
- kodablah 14y agoThat 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.