所以可能有一个abc用于多次付款,现在我有:
//find abc id for each payment id
Map<Long, Integer> abcIdToPmtId = paymentController.findPaymentsByIds(pmtIds)
.stream()
.collect(Collectors.toMap(Payment::getAbcId, Payment::getPaymentId));
Run Code Online (Sandbox Code Playgroud)
但后来我认为这个chould有重复的键,所以我希望它返回一个
Map<Long, List<Integer>> abcIdToPmtIds
Run Code Online (Sandbox Code Playgroud)
哪个条目将包含一个abc和他的几笔付款.
我知道我可以使用,groupingBy但我认为我只能得到Map<Long, List<Payments>>.
所以我知道我可以用两.stream行来做到这一点,但不确定我是否只能用一行来做到这一点.这就是我所拥有的:
List<Long> abcIds= abcController.findByUserIds(userIds)
.stream()
.map(Abc::getAbcId)
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
但我希望abcIds成为一个整数列表,因为稍后我会使用它的其他函数.我知道我可以写这样的另一行来将List of Long转换为整数列表:
List<Integer> abcIntIds= abcIds.stream()
.map(Long::intValue)
.collec?t(Collectors.toList(??));
Run Code Online (Sandbox Code Playgroud)
但有没有办法把它写得更优雅?