The contains() method is utilized to check whether a certain element is present in the list or not.
Method Definition: def contains(elem: Any): Boolean
Return Type: It returns true if the element present in the contains method as argument is also present in the stated list else it returns false.
Example #1:
// Scala program of contains() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a list val m1 = List(1, 3, 5, 2) // Applying contains method val res = m1.contains(1) // Displays output println(res) } } |
chevron_right
filter_none
Output:
true
Example #2:
// Scala program of contains() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a list val m1 = List(1, 3, 5, 2) // Applying contains method val res = m1.contains(7) // Displays output println(res) } } |
chevron_right
filter_none
Output:
false
Recommended Posts:
- Scala map contains() method with example
- Scala Set contains() method with example
- Scala Queue contains() method with example
- Scala SortedSet contains() method with example
- Scala Stack contains() method with example
- Scala TreeSet contains() method with example
- Scala SortedMap contains() method with example
- Scala Mutable SortedMap contains() method with example
- Scala List take() method with example
- Scala List splitAt() method with example
- Scala List drop() method with example
- Scala List takeWhile() method with example
- Scala List takeRight() method with example
- Scala List sum() method with example
- Scala List size() method with example
- Scala List product() method with example
- Scala List min() method with example
- Scala List max() method with example
- Scala List filter() method with example
- Scala List filterNot() method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

