Why is String.hashCode() cached?
String is immutable, so its hash code never changes. Java computes it once and reuses it to speed up lookups in collections like HashMap.
🔥 Launch Offer: Interview Preparation Bundle @ ₹2,499 ₹9,999 • 75% OFF. Offer expires in
🔥 Launch Offer: Interview Preparation Bundle @ ₹2,499 ₹9,999 • 75% OFF. Offer expires in
Interview Preparation Bundle @ ₹2,499 ₹9,999
String is immutable, so its hash code never changes. Java computes it once and reuses it to speed up lookups in collections like HashMap.