• Post Reply Bookmark Topic Watch Topic
  • New Topic

Same elements in HashMap  RSS feed

 
Skanda Raman
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.

 
Wouter Oet
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!