Stack class, the exists() method is utilized to check whether a predicate holds for any of the elements of the stack.
Method Definition: def exists(p: (A) => Boolean): Boolean
Return Type: It returns true if the predicate holds true for any of the elements of the stack or else returns false.
Stack(1, 3, 2, 7, 6, 5) Element divisible by 7 exists: true
Stack(1, 3, 2, 7, 6, 5) Element 10 exists: false
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.