场景一:对集合的去重聚合操作
List<String> ips = Lists.newArrayList("10.194.39.102_6408","10.194.39.110_6406","10.194.39.110_6407");
//对集合按ip分组,并将同一个ip的端口聚合
Map<String, String> result = ips.stream().collect(Collectors.toMap(ip -> ip.split("_")[0],
ip -> ip.split("_")[1],(areaNamUp, areaNamDown) -> areaNamUp + "," + areaNamDown));
最后可以得到,以ip为key,value为逗号隔开的端口字符串,可以很清楚的看到哪些ip,及ip涉及到的端口。