美文网首页
guava list to map

guava list to map

作者: crocodile_b | 来源:发表于2017-01-17 14:56 被阅读1280次

1、list到Id唯一确定的map,map的KEY是LeadClient中的ContactId

Map<Long, LeadClient> clientLevelMap = Maps.uniqueIndex(leadClients, new Function<LeadClient, Long>() {
                    public Long apply(LeadClient leadClient) {
                        return leadClient.getContactId();
                    }
                });

2、list到多个id的列表,key也来自LeadClient

ImmutableListMultimap<Long, OrderItem> orderItemMap = Multimaps.index(orderItems, new Function<OrderItem, Long>(){
                public Long apply(OrderItem orderItem){
                    return orderItem.getOrderId();
                }
            });

相关文章

网友评论

      本文标题:guava list to map

      本文链接:https://www.haomeiwen.com/subject/hzvmbttx.html