1

I have one ArrayList of Integer, extracted from a MapDB map, with this code:

ArrayList<Integer> idOffUser=users.get(myUser).getOffers();

It's a list of ids. I have another ConcurrentNavigableMap from the same db, called auctions. In this map for every object which mantains I have an ArrayList of Integer, called offId, which has a list of unique integers, each one representing a specific offer. Every offId it's reffered to a specific object (an auction) of that map.
In every offId there can be (or not!) a match for some elements of idOffUser, so I need to extract the objects in auctions whose offId has at least a match with an element of idOffUser, excluding the duplicates, because I only need to know in what auction an user put an offer, but an user can put multiple offers in an auction.
As a result of this method I need to have an ArrayList with every auction object in which an user put at least an offer.
So far, I know I can access an arraylist of offers in auctions in this way:

for (Auction key : auctions.values())
key.getOffId();  
JamieITGirl
  • 161
  • 1
  • 11

1 Answers1

1

Something like this shoul do the trick:

Set<Integer> uniqueIds = new HashSet<>();
for (Auction key : auctions.values())
    uniqueIds.addAll(key.getOffId()); 
List<Integer> idsOfUsersWithAuctions = idOffUser.stream().filter(id -> uniqueIds.contains(id)).collect(Collectors.toList());
Patrick Zinner
  • 356
  • 4
  • 17
  • Thank you but I'm afraid your code is not what I need. I don't need a list of users with auctions, I need an ArrayList of auctions in which an user put at least an offer, because I have to extract data regarding that auction. To clarify, offers have unique ids. Every user has an ArrayList of id of offers which he put, every auction has an ArrayList of offers. – JamieITGirl Feb 06 '18 at 13:53
  • Can you explain what this instruction do? `idOffUser.stream().filter(id -> uniqueIds.contains(id)).collect(Collectors.toList());` – JamieITGirl Feb 06 '18 at 19:32