• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I verify that values from HashMap are equal?  RSS feed

 
Dana Ucaed
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers,

I had a map:
For example: 'a' 1
'b' 2
'c' 1


How can I verify that all values from HashMap are equal?






Thanks Thanks



 
Paweł Baczyński
Bartender
Posts: 2074
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say you need to get a collection of values (there is a method in Map that does this) and check whether all values in the collection are the same.
What do you want to get for empty map?
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dana Ucaed wrote:. . .. . .
That shou‍ld readPlease tell us how you are defining equality; you will probably find that any built‑in Java® solution will use the equals() method. Please have a look at the Map interface, and see how you can get all values in some sort of Collection. Use of that Collection might be one way to work out whether all values are equal, but it will probably give you incorrect results if you haven't overridden equals() correctly.
If that doesn't help, how would you think you would test all values for equality?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!