• Post Reply Bookmark Topic Watch Topic
  • New Topic

List.addAll() not behaving as expected when adding objects from a Concurrent HashMap  RSS feed

 
devaki hanumante
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have the below code -

Class CardCache
--------------------
private static ConcurrentMap<CacheKey,List<Card>> CardMap = new ConcurrentHashMap<CacheKey, List<Card>>();


Service Class
---------------
List<Card> Cards = null;
Cards = CardCache.getCards("USA"); //Lets say this returns 5 cards
Cards.addAll(CardCache.getRateCards("NA")); //This returns 1. So I should have 6 cards in my Cards list. But along with this, my CardCache is also getting updated with a duplicate card having the value "NA"

I am not sure why this is the case.
Any help is appreciated.

 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difficult to judge why it is happening. Need more code to know.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start with some basic debugging: print out the result of the get("NA") call.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!