• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Set problem

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


when this code runs print
ram2=5 ram=4
and size 2 but here no hashCode is used so it should print size 5

please help

thanks in advance
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sweety sinha wrote:

when this code runs print
ram2=5 ram=4
and size 2 but here no hashCode is used so it should print size 5

please help

thanks in advance



Hi.

Hashmap doesnt accept duplicate keys. So your hashmap s would only have 2 because you only have two keys "ram" and "ram2".
The other put operation wasn't successful because it has duplicate keys. By the way I think if it is not successful in putting it to the hashmap it will return false.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

here no hashCode is used so it should print size 5



You are using String as keys and the String class has an implementation of equals and hashCode method which will be used by the HashMap...
 
sweety sinha
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Ankit & Joshua Ebarvia for quick response
reply
    Bookmark Topic Watch Topic
  • New Topic