//求平均 方法一: groupByKey
textFile.mapToPair(line -> new Tuple2<>(line.split(" ")[0], Integer.parseInt(line.split(" ")[1])))
.groupByKey()
.mapToPair(info -> {
double sum = 0;
double count = 0;
Iterator<Integer> it = info._2().iterator();
while (it.hasNext()) {
sum += it.next();
count++;
}
double ave = sum / count;
return new Tuple2<>(info._1(), ave);
})
.collect()
.forEach(System.out::println);
//求平均 方法二: combineByKey
textFile.mapToPair(line -> new Tuple2<>(line.split(" ")[0], Int