zent Zent

Greenhorn
+ Follow
since Sep 13, 2015
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by zent Zent


Hello Rajeev Rnair,

Would it be possible to contact you through email? I have some questions about preparing for Java certifications.

Thank you

Thank you, I will fix that!
3 years ago


Thank you, that makes it very clear!!
3 years ago
Thank you for your time!

I have a Hashmap that has keys of of type Account (custom class) and the values are strings. The Account class has the following private variables:
1) name (String type)
2) account number (String type)
3) balance (type double).

Following are the files:

My Question:

When I ran this program, I expected the output to be:

A, 142463, 677489

but, I am getting the following output:

A 14243 46778.0

My understanding was that when a duplicate key is added (as defined in the equals() method) to a hash map, it replaces the old (key,value) pair.

I then recreated the old Account object and tried to get its key value. The output was as below:

A 14243 46778.0
Value for Account c = 23

That is, its keeping the old key (A 14243 46778.0), but replacing its previous value (444) with the value of the newly added Account (23).

Also, when I check for "444" in the map, I am no longer able to obtain the corresponding key as it has been replaced with 23.

I would be grateful in any help in fixing this issue.

Thank you!"
3 years ago