1

我有一个整数数组列表,从 MapDB 地图中提取,代码如下:

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

这是一个ID列表。我有另一个来自同一个数据库的 ConcurrentNavigableMap,称为拍卖。在这张地图中,对于每个包含的对象,我都有一个整数数组列表,称为 offId,它有一个唯一整数列表,每个整数代表一个特定的报价。每个 offId 它都被引用到该地图的特定对象(拍卖)。
在每个 offId 中,可能(或没有!)idOffUser 的某些元素匹配,因此我需要在拍卖中提取其 offId 至少与 idOffUser 元素匹配的对象,不包括重复项,因为我只需要知道用户在什么拍卖中提出了要约,但用户可以在拍卖中提出多个要约。
作为这种方法的结果,我需要一个 ArrayList 与用户至少提出报价的每个拍卖对象。
到目前为止,我知道我可以通过这种方式访问​​拍卖中的报价数组列表:

for (Auction key : auctions.values())
key.getOffId();  
4

1 回答 1

1

像这样的东西应该可以解决问题:

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());
于 2018-02-06T13:36:20.727 回答