您好,我有一種情況,我有權限列表(權限列表),我需要將此列表轉換為地圖 Map<String, List of Permission>。在地圖中,鍵是“類型”,相同的對象將被插入到相應的列表值中。我編寫的代碼運行良好,但它存儲了重復的權限對象。我需要將唯一對象存儲到列表中。我怎樣才能做到這一點。當前代碼如下,它在列表中存儲重復對象:listofRights .stream() .filter(permission-> StringUtils.isNotEmpty(permission.getType())) .collect(Collectors .groupingBy(Permission::getRole, Collectors.mapping(identity(), Collectors.toList())));
1 回答

ibeautiful
TA貢獻1993條經驗 獲得超6個贊
我想你需要改變Collectors.toList()
與Collectors.toSet()
假設Permission
工具equals/hashCode
添加回答
舉報
0/150
提交
取消