Open In App

Scala Listset apply() method with examples

Last Updated : 03 Nov, 2019
Improve
Improve
Like Article
Like
Save
Share
Report


In Scala ListSet, apply() method is utilized to check if the given element is present or not in the listSet.

Method Definition: final def apply(elem: A): Boolean

Return Type: True if element is present else false.

Example 1:




// Scala program of apply() 
// method 
import scala.collection.immutable._
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating a listSet
        val m1 = ListSet(1, 3, 5, 2
          
        // Applying apply method 
        val res = m1.apply(3
          
        // Displays output 
        println(res) 
      
    


Output:

true

Example 2:




// Scala program of apply() 
// method 
import scala.collection.immutable._
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating a listSet
        val m1 = ListSet(1, 3, 5, 2
          
        // Applying apply method 
        val res = m1.apply(3
          
        // Displays output 
        println(res) 
      
    


Output:

true


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads