Java - Map 自定义排序 Lambda 之 Comparator

Comparator> comp = Comparator.comparingInt(item -> item.getValue().getPercent());
Map map = Maps.newHashMap();

RxGraphVO.SlbNode.SlbItem slbItem1 = new RxGraphVO.SlbNode.SlbItem();
slbItem1.setApiId("a");
slbItem1.setPercent(50);

RxGraphVO.SlbNode.SlbItem slbItem2 = new RxGraphVO.SlbNode.SlbItem();
slbItem2.setApiId("b");
slbItem2.setPercent(50);

map.put("it1", slbItem1);
map.put("it2", slbItem2);

map.entrySet().stream().sorted(comp);
map.entrySet().forEach(item -> System.out.println(item.getKey()));

你可能感兴趣的:(#,Java,Java,lambda,comparator,sort,map)