【发布时间】:2015-06-14 14:27:31
【问题描述】:
我能做到:
Map<Long, MyBean> mappedbean = Maps.uniqueIndex(myBeanList, toId);
在哪里
private final Function<BeanWithId, Long> toId=
new Function<BeanWithId, Long>() {
public Long apply(BeanWithId beanWithId) {
return beanWithId.getId();
}
};
但是我如何创建子列表的映射,所以像这样:
Map<Long, List<MyBean>> mappedbean = Maps.somethingSomething(myBeanList, toId);
其中 id 不是 bean 上的唯一标识符。
一个无聊的旧 for 循环?
【问题讨论】:
-
一个“无聊的老” for 循环通常更直接和可读...
标签: java collections hashmap guava