aspose file tools
The moose likes Other JSE/JEE APIs and the fly likes String hash Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply Bookmark "String hash" Watch "String hash" New topic
Author

String hash

Abhijit Jawale
Greenhorn

Joined: Jun 01, 2004
Posts: 4
When String hash is computed?
If I am inserting 10 million strings in a HashSet then will it compute it for each insertion or it would have already computed hash (as String is immutable object)?
Luciano A. Pozzo
Ranch Hand

Joined: Jun 20, 2005
Posts: 112
The hash will be computed for every object added in the set.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19232

Although officially it is unspecified, String has a transient field for the hash code. This field is calculated when hashCode is called and the field is 0. So unless the hash code of a String actually 0 it will be calculated only once.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: String hash
 
Similar Threads
hashcode() and equals()
equals - hashcode
How to System.out.println the string reference
String object ?
immutable objects....