Product2 is a trait in Scala, which is a Cartesian product of two elements. In build-in classes it can be considered as tuple of two elements. The Linear Supertypes here are Product, Equals, Any, and the sub-class here is Tulple2. Product2 extends Product like below:
Product2[+T1, +T2] extends Product
Here, T1 and T2 are the types of the elements.
Now, lets see some examples.
Here, _1 is the extension for the first element of the product stated above and _2 is the extension for the second element of the product.
List(Nidhi, Nisha, Preeti)
Hence, Iteration is easily done here.
- Scala Tutorial – Learn Scala with Step By Step Guide
- Scala Map
- Scala | Either
- Set in Scala | Set-2
- Set in Scala | Set-1
- Scala | map() method
- Recursion in Scala
- Scala Int +(x: Int) method with example
- while and do while Loop in Scala
- Scala Lists
- StringBuilder in Scala
- Scala | Option
- Scala | Literals
- Scala Map max() method with example
- Scala | Ranges
- Scala Map min() method with example
- Scala Map take() method with example
- Scala Int >>(x: Int) method with example
- Scala sum Map values
- Scala Int >=(x: Int) method with example