• Post Reply Bookmark Topic Watch Topic
  • New Topic

String HashCode  RSS feed

 
Greenhorn
Posts: 1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody tell me why String's hashCode is calculated with 31 ?
what is the reason behind dis ?
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

There's no really simple answer to that question, but you're not the first person asking it. Have a look at this: Why do hash functions use prime numbers?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!