r/programming • u/Eirenarch • Nov 18 '13
TIL Oracle changed the internal String representation in Java 7 Update 6 increasing the running time of the substring method from constant to N
http://java-performance.info/changes-to-string-java-1-7-0_06/
1.4k
Upvotes
View all comments
Show parent comment
2
u/danielkza Nov 18 '13 edited Nov 18 '13
You're correct that the great majority of people will understand what you meant perfectly, but if one was to be pedantic, saying the running time changed 'to N' can mean:
a) It is exactly N for a length N. Doesn't make much sense due to the lack of time units. b) The lower and upper time bounds are of order N, which means the running time is always the length of the string times a constant, usually denoted Θ(N) in complexity notation.
When what you want is probably O(N) for worst case bound, but only because of something subtle: the JVM probably does not make a copy if it detects you want a substring which is actually the whole string, making it a constant time case.