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




discard( ) FUNCTION


The 'discard( )' Function is used to remove a particular value from the Set.


Example :


x = {"Mohan", "Kriti", "Salim"}
x.discard("Kriti")
print(x) 


Output :



  {'Mohan', 'Salim'}

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


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

java_Collections

Next, we have used the 'discard( )' Function that searches for the name 'Kriti' and removes it from the Set.


x.discard("Kriti")

java_Collections

And we get the below output,


{'Mohan', 'Salim'}