since the flatmap function generates JavaRDD<Tuple2<String, Double>> and I want them to be in JavaPairRDD<String, Double> before the next stage of the code, therefore, the map function is used. If there are better syntactical support for this, I am more than glad to know and change the code.