• 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

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

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Difficult to judge why it is happening. Need more code to know.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start with some basic debugging: print out the result of the get("NA") call.
 
reply
    Bookmark Topic Watch Topic
  • New Topic