Guava使用笔记multiMap

时间:2022-07-29 20:47:49
今天team里的同事们讨论guava中有没有这样一种工具,能够将一根modelList按照model中指定的某个属性进行分组汇总.
key为属性,value为含有当前属性的modelList,guava中还真有.代码如下.

ImmutableListMultimap, GlVoucherLineModel> index = Multimaps.index(glVoucherLineModels, new Function, Integer>() {
@Override
public Integer apply(GlVoucherLineModel input) {
return input.getId();
}
});