aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes String hash Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
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: 19760
    
  20

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String hash