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 Map
- Set in Scala | Set-2
- Set in Scala | Set-1
- Scala | Either
- Scala Int %(x: Int) method with example
- Scala Set take() method with example
- BitSet in Scala
- Scala Set min() method with example
- Scala Set sum() method with example
- Scala | Variances
- HashSet In Scala
- Scala | REPL
- Scala | Traits
- Scala Stream
- Hello World in Scala
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.