Scala Listset apply() method with examples

Last Updated : 3 Nov, 2019
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
// 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
// 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
Comment

Explore