Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Same elements in HashMap  RSS feed

 
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have requirement to breakdown the records in a map into multiple records. To be more precise,

I have the map with below values.

name=Y
cost=300

name=Z
cost=100

My max Limit of COST is just 100. So the map should break up and consist as below

name=Y
cost=100

name=Y
cost=100

name=Y
cost=100

name=Z
cost=100

I tried code snippet below, but as map doesn't allow duplicate keys, was not sure how to proceed with this. please suggest is there any way.

 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you create a class for it and implement the correct hashcode and equals methods? Also you could use a generic HashMap.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!