48 - Spark RDD - Tuples

Опубликовано: 23 Февраль 2026
на канале: Rishi’s programming channel
481
7

‪@backstreetbrogrammer‬

--------------------------------------------------------------------------------
Chapter 09 - Spark RDD - Tuples
--------------------------------------------------------------------------------
In Scala, a tuple is a value that contains a fixed number of elements, each with its own type. Tuples are immutable. Tuples are especially handy for returning multiple values from a method.

A tuple with two elements can be created as follows:

val person = ("John", 25)

This creates a tuple containing a String element and an Int element. The inferred type of person is (String, Int).

Tuples are of type Tuple1, Tuple2, Tuple3 and so on. There currently is an upper limit of 22 in the Scala if we need more. For each TupleN type, where 1 := N := 22, Scala defines a number of element-access methods.

Example:

final var tuple2JavaRDD = myRdd.map(line -: new Tuple2(line, line.length()));


Github: https://github.com/backstreetbrogramm...

Apache Spark for Java Developers Playlist:    • Apache Spark for Java Developers  
Top Java Coding Interview Problems Playlist:    • Top Java Coding Interview Problems  
Java Serialization Playlist:    • Java Serialization  
Dynamic Programming Playlist:    • Dynamic Programming  

#java #javadevelopers #javaprogramming #apachespark #spark