【发布时间】:2020-11-13 19:43:34
【问题描述】:
我有一个字符串列表
List <String> Ids = [id1, ids2, id3];
还有一个函数
public List<String> getDays(String id) {
// makes api call and fetch all the days in a list where id is present
return list;
}
现在我想对 ID 的每个列表元素执行 getDays 函数并将其存储在地图中
Map<String, List<String> where String would be my Id from List(IDs) and
List<String> would be the corresponding return value of getDays
function on each Id
获得地图后,我可以将其用于进一步的操作,例如过滤地图或检查我在一周中某一天的身份。
我知道可以使用 for 循环来完成,但我更想知道是否还有其他方法,例如流或地图实用程序。
【问题讨论】:
标签: java collections java-stream