How to use yield keyword in scala and why it is used instead of println?

0 votes
Can anyone explain how to use yield keyword in scala and why it is used instead of println?
Jul 5 in Apache Spark by gandhi
72 views

1 answer to this question.

0 votes

Hi,

The yield keyword is used because the result of each for loop iteration is stored in a list (vector) or it collects the list of output and saves it in the vector. Below an example to see the code and its input:

The above is a for loop with yield function and you can see the below code to store the output in a vector form.

answered Jul 5 by Gitika
• 25,340 points

Related Questions In Apache Spark

0 votes
1 answer

How will you explain yield keyword in Scala?

Hi, Yield keyword can be used either before ...READ MORE

answered Jul 5 in Apache Spark by Gitika
• 25,340 points
31 views
0 votes
1 answer

Which syntax to use to take the sum of list of collection in scala?

Hi, You can see this example to get ...READ MORE

answered Jul 5 in Apache Spark by Gitika
• 25,340 points
39 views
0 votes
1 answer

How can you use "for" statement in scala to print list from collection?

Hi, You can use for loop in scala using ...READ MORE

answered Jul 5 in Apache Spark by Gitika
• 25,340 points
36 views
0 votes
1 answer
0 votes
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,710 points
3,321 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,710 points
396 views
0 votes
10 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyFr ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
16,365 views
0 votes
1 answer

How to use Scala anonymous functions and why do we use it?

Hi, Anonymous functions in Scala is the lightweight ...READ MORE

answered Jul 26 in Apache Spark by Gitika
• 25,340 points
69 views
0 votes
1 answer

What is the work of Yield Keyword in Scala?

Hey, Used with a loop, yield produces a value for ...READ MORE

answered Jul 26 in Apache Spark by Gitika
• 25,340 points
41 views