aspose file tools*
The moose likes Java in General and the fly likes how to define hashCode in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to define hashCode in java?" Watch "how to define hashCode in java?" New topic
Author

how to define hashCode in java?

Rd Dari
Ranch Hand

Joined: Feb 22, 2010
Posts: 202

Hi all Ranchers,
There is java file and according to output I want to know what is the base of hashCode. I do not know exact about what does hashCode() method do.



The out is : -

Thanks in advanced!!.
Gaurangkumar Khalasi
Ranch Hand

Joined: Jun 02, 2012
Posts: 186
Rd Dari wrote: I do not know exact about what does hashCode() method do.

http://en.wikipedia.org/wiki/Java_hashCode()
Yogesh Gnanapraksam
Ranch Hand

Joined: Dec 17, 2009
Posts: 133
It is better to read the documentation about the hashCode method first.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4241
    
    7

Yogesh Gnanapraksam wrote:It is better to read the documentation about the hashCode method first.

Might as well link to the current documentation: java.lang.Object#hashCode() (although I doubt it's changed).
Rd Dari
Ranch Hand

Joined: Feb 22, 2010
Posts: 202

ya you all are right.

I must read the hashCode() method to understand it clearly.


Thanks a lot.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36514
    
  16
Why on earth are you using Enumeration and Vector, which are regarded as outmoded? Use Iterator and ArrayList instead.
Rd Dari
Ranch Hand

Joined: Feb 22, 2010
Posts: 202

it was different post by mistake I mixed it in hashCode() method
Sorry!!!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36514
    
  16
If it was an interview question, why didn’t you say so? Those questions are completely unrelated to real life. You can’t say what the capacity of a Vector it, unless you have seen all its method calls. Even then you might not know it. You are better off going on about not knowing implementation details, and how you don’t worry about capacity because you know it changes to accommodate whatever you put in it. Also say you usually use ArrayList, which might have a different mechanism for increasing capacity. Mentioning the ensureCapacity method and how it speeds up adding would be a good move.
Rd Dari
Ranch Hand

Joined: Feb 22, 2010
Posts: 202

Actually I am asking about the output

enumeration days:
-1807319568
-1984635600
687309357
-897468618
1553582752
2112549247
-2049557543

how it is coming for program

Please reply it.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4241
    
    7

It's just printing the hash codes for those Strings. The documentation for java.lang.String#hashCode() tells you how that's calculated.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36514
    
  16
It’s printing the hash codes in decimal. I might prefer to use… and print the hash codes in hexadecimal.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to define hashCode in java?
 
Similar Threads
hashCode() problem
Enumeration
Hash Table - Sorting
remove item in shopping cart
Enumeration