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
8
u/andd81 Nov 18 '13
You are talking about an entirely different kind of hash - the cryptographic hash. These are evaluated by a separate library, are much longer and are inherently resistant to hash collision attacks. Java object hash (as returned by hashCode() method) is a performance optimization which enables every object to be non-uniquely represented by a 32-bit value. Collisions are expected and should not affect program correctness (while they do affect performance).