Tuples in scala:
Tuple is the collection class in Scala which can hold multiple values with same or different types together.
Syntax:
tuples are declared within braces "()"
Note:
tuple can hold up-to 22 values/elements, since the scala compiler is smart enough, so dont need to specify the lengh explicitly.
Example:
Student details with three elements
Note:
To access values inside the tuple is through position of elements _1,_2,......_22.
Syntax:
val studentname = studentinfo._1
Assign values of tuples to multiple variables in one line:
We can also assign the tuple values to multiple variables at once
Syntax:
Tuple is the collection class in Scala which can hold multiple values with same or different types together.
Syntax:
tuples are declared within braces "()"
Note:
tuple can hold up-to 22 values/elements, since the scala compiler is smart enough, so dont need to specify the lengh explicitly.
tuple1,tuple2.....tuple22Useful at below situations:
- if you want a common reference
- Ex: student details like name,age, etc.,
- Performance wise is better than list
Example:
Student details with three elements
Note:
.getClass function is used to return data type of variableAccess values of Tuple in Scala:
To access values inside the tuple is through position of elements _1,_2,......_22.
Syntax:
<<tuple_variable>>._1Example:
<<tuple_variable>>._2
<<tuple_variable>>._3...etc
val studentname = studentinfo._1
Assign values of tuples to multiple variables in one line:
We can also assign the tuple values to multiple variables at once
Syntax:
val (var1,var2,...) = tupleholderExample:
Good Blog,Thanks for sharing this informative article.
ReplyDeleteBig Data Hadoop Online Training | Big Data Hadoop Training | Hyderabad
Nice post.
ReplyDeleteScala online training
Scala training
SCCM online training
SCCM training
SCOM online training
SCOM training
SSAS online training
SSAS training
SSIS online training
SSIS training
SSRS online training
SSRS training
tableau online training
tableau training
Teradata online training
Teradata training
Windows admin online training
Windows admin training
Wordpress online training
Great, thanks for sharing this post.Much thanks again. Awesome.
ReplyDeleteSAP ABAP training
SSAP PP online training
data science training
teradata training
oracle bpm training
angular js training
sql server dba training
nice post.scom training
ReplyDeletescom online training
Really enjoyed this article.Much thanks again. Want more
ReplyDeletebest machine learning course in india
best machine learning course online
Borgata Hotel Casino & Spa Announces 2021 Opening Date
ReplyDeleteThe 안양 출장샵 Borgata Hotel Casino & 수원 출장마사지 Spa in 울산광역 출장안마 Atlantic City, New Jersey will open 안산 출장마사지 its doors for business 전라남도 출장안마 on Thursday, September 7, 2021.