DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Joseph Berdat Guest

    implement int hashCode()

    How to implement this method for my own classes used as key in a HashMap.
    Thanks.



  2. #2
    Paul Clapham Guest

    Re: implement int hashCode()

    You need to return an integer that will satisfy these two conditions:

    (1) for any particular object in the class, your method will always return
    the same value.

    (2) for different objects in the class, your method should have a good
    chance of returning different values.

    PC2

    "Joseph Berdat" <jberdat@eim.ch> wrote in message
    news:3b24d543@news.devx.com...
    > How to implement this method for my own classes used as key in a HashMap.
    > Thanks.
    >
    >




  3. #3
    X Guest

    Re: implement int hashCode()


    "Joseph Berdat" <jberdat@eim.ch> wrote:
    >How to implement this method for my own classes used as key in a HashMap.
    >Thanks.
    >
    >


    The book 'Effective Java' by Josh Bloch explains in detail the contract of
    equals() and hashCode() and give excellent guidelines and examples on how
    to implement them. This chapter is available online somewhere on the SUN
    site.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links