Scala Listset apply() method with examples
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 m 1 = ListSet( 1 , 3 , 5 , 2 ) // Applying apply method val res = m 1 .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 m 1 = ListSet( 1 , 3 , 5 , 2 ) // Applying apply method val res = m 1 .apply( 3 ) // Displays output println(res) } } |
Output:
true
Contact Us