java8中使用Lambda表达式

List<RegionCountBo> regionCounts = new ArrayList<>();
        Map<String, RegionCountBo> map = regionCounts.stream().collect(Collectors.toMap(p->p.getRegionCode(),p->p));

List<Entity> list = new ArrayList<>();
Map<Integer, String> map = list.stream().collect(Collectors.toMap(Entity::getId, Entity::getType));

List<Object[]> regionCounts = deviceRepository.countGroupByRegion();
        Map<String, RegionCountBo> regionCountsMap = regionCounts.stream().collect(Collectors.toMap(p->(String)p[1],
                p->new RegionCountBo((String)p[1],null,Integer.parseInt(p[0].toString()),null,null)));

regionCountBos.sort((RegionCountBo h1, RegionCountBo h2) -> h2.getOnlineRate().compareTo(h1.getOnlineRate()));
发布了296 篇原创文章 · 获赞 70 · 访问量 55万+

猜你喜欢

转载自blog.csdn.net/feicongcong/article/details/102632685