Monica Shiralkar wrote:Why does the java code require the String array with splitted words to be converted into a List (using asList method)
Because the
flatMap() method requires a
FlatMapFunction, which is a functional interface with a method that returns an
Iterator. You can't get an
Iterator from an array, only from an
Iterable, such as a
List.
Why does the scala not require mapToPair instead of map method as required by the java code
Because Scala has a concept known as 'implicit conversions'. An RDD of tuples is automatically converted so that you can call
PairRDDFunctions on it. This is not possible in Java, so you need to tell Java explicitly that you want to work on an RDD of tuples after remapping the elements.
Why does the scala code not require new Tuple2 (word, 1) instead of (word, 1).
Because tuples are a built-in type in Scala. When you write
(a, b), it means the exact same thing as
new Tuple2(a, b).