Advertisement
mehedi2022

Untitled

Sep 13th, 2022
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. // What's the difference between tuples and lists?
  2.  
  3. // Tuples is a Type of data that consists of several Pieces of other data. On the Other hand list is most common type of collection in scala. Represents an arbitrary number of Piece of data. All piece of data in list must be in the same type. A list has a variable size while a tuple has a fixed size. Tuples are typed like tupe._1, list is types list(0)
  4.  
  5. Lists are mutable(values can be changed) whereas tuples are immutable(values cannot be changed). This means that tuples cannot be changed while the lists can be modified. Tuples are more memory efficient than the lists.
  6. Tuple are of type Tuple1 , Tuple2 ,Tuple3 and so on. There is an upper limit of 22 for the element in the tuple in the scala, if you need more elements, then you can use a collection, not a tuple.
  7.  
  8. // Q. What are the benefit of using Tuples in Scala
  9.  
  10. //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.
  11.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement