Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




intersection( ) FUNCTION


As the name suggests, the 'intersection( )' Function takes the values from both the sets and only value that is common in both Sets are taken and initialised to the third Set.


Since, 'Kriti' is the common value in both the Sets, 'intersection( )' Function would just take the name 'Kriti'.


Example :


x = {"Mohan", "Kriti", "Salim"}
y = {"Sia", "Andrew", "Kriti"}
z = x.intersection(y)
print(z) 


Output :



  {'Kriti'}

So, in the above code we have created a 'Set' and initialised to the variable 'x'.


x = {"Mohan", "Kriti", "Salim"}

java_Collections

Then what we have done is, put the names, 'Sia', 'Andrew' and 'Kriti' in another set 'y'.


y = {"Sia", "Andrew", "Kriti"}

java_Collections

And used the 'intersection( )' Function next to take the common value and initialise to the third variable 'z'.


z = x.intersection(y)

And since, 'Kriti' is present in both the Sets, only 'Kriti' will be present in the new Set 'z'.


java_Collections

And we get the below output,


{'Kriti'}