How to find values common to two sets in Scala

0 votes
How to determine the values common to two certain sets in Scala?
Jul 31, 2019 in Apache Spark by Rashmi
1,689 views

1 answer to this question.

0 votes

Hey,

There are two ways to find the values which are mention below:

Let's take two new sets

scala> var a=Set(1,4,3,4,2)

a: scala.collection.immutable.Set[Int] = Set(1, 4, 3, 2)

scala> var b=Set(7,9,8,2,8)

b: scala.collection.immutable.Set[Int] = Set(7, 9, 8, 2)
  • Using Set.&() Method

You can call &() on one set, and pass another to it.

scala> a.&(b)

res10: scala.collection.immutable.Set[Int] = Set(2)
  • Using Set.intersect() Method​

scala> a.intersect(b)

res11: scala.collection.immutable.Set[Int] = Set(2)

scala> b.intersect(a)

res12: scala.collection.immutable.Set[Int] = Set(2)

If you want to know more about Apache Spark Scala, It's highly recommended to go for the Apache Spark Certification today.

answered Jul 31, 2019 by Gitika
• 65,890 points

Related Questions In Apache Spark

0 votes
1 answer

How do find Max and Min values in a set in Scala?

Hey, Here is the example of which will return ...READ MORE

answered Jul 30, 2019 in Apache Spark by Gitika
• 65,890 points
4,097 views
0 votes
1 answer

How to concatenate sets in Scala?

Hey, Yes, there are two ways of doing ...READ MORE

answered Jul 31, 2019 in Apache Spark by Gitika
• 65,890 points
1,769 views
0 votes
1 answer

How to find max value in pair RDD?

Use Array.maxBy method: val a = Array(("a",1), ("b",2), ...READ MORE

answered May 26, 2018 in Apache Spark by nitinrawat895
• 11,380 points
7,923 views
+1 vote
8 answers

How to replace null values in Spark DataFrame?

Hi, In Spark, fill() function of DataFrameNaFunctions class is used to replace ...READ MORE

answered Dec 15, 2020 in Apache Spark by MD
• 95,460 points
75,192 views
+1 vote
2 answers
+1 vote
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
• 11,380 points
10,910 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
• 11,380 points
2,443 views
+2 votes
11 answers

hadoop fs -put command?

Hi, You can create one directory in HDFS ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
108,227 views
0 votes
1 answer

How to implement two level loop in scala?

Hi, You can use two level loops using the ...READ MORE

answered Jul 5, 2019 in Apache Spark by Gitika
• 65,890 points
715 views
0 votes
1 answer

How to declare sets with value in Scala?

Hey, You can follow this code: scala> var s=Set(1,4,4,3) s: ...READ MORE

answered Jul 30, 2019 in Apache Spark by Gitika
• 65,890 points
646 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP