implement int hashCode()


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: implement int hashCode()

  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.

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center