The exists() method is utilized to check if the given predicate satisfy the elements of the list or not.
Method Definition: def exists(p: (A) => Boolean): Boolean
Return Type: It returns true if the stated predicate holds true for some elements of the list else it returns false.
Example #1:
// Scala program of exists() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a list val m1 = List(1, 2, 3, 4, 5) // Applying exists method val result = m1.exists(y => {y % 3 == 0}) // Displays output println(result) } } |
chevron_right
filter_none
Output:
true
Example #2:
// Scala program of exists() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a list val m1 = List(1, 2, 3, 4, 5) // Applying exists method val result = m1.exists(y => {y % 9 == 0}) // Displays output println(result) } } |
chevron_right
filter_none
Output:
false
Recommended Posts:
- Scala Iterator exists() method with example
- Scala Map exists() method with example
- Scala Set exists() method with example
- Scala Queue exists() method with example
- Scala SortedSet exists() method with example
- Scala SortedMap exists() method with example
- Scala ListSet exists() method with example
- Scala Stack exists() method with example
- Scala TreeSet exists() method with example
- Scala immutable TreeSet exists() method with example
- Scala Mutable SortedMap exists() method with example
- Scala BitSet exists() 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
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.

