BitSet exists() Method in Scala with Example

Here, we will learn about the BitSet exists() method in Scala along with syntax and examples.
Submitted by Shivang Yadav, on October 12, 2020

BitSet in Scala is a special collection of positive integers. Scala programming language has a huge library containing a lot of utility functions to help working with data structure easy.

BitSet exists() method

The exists() method in Scala is used to check whether an element exists in the collection (BitSet) that satisfies the given condition.

The method returns a boolean value based on the condition. Returns true if any element of the BitSet satisfies the condition otherwise returns false.

Syntax:

BitSetName.exists(x => {condition})

Return Type:

The method returns a Boolean value depending on the condition.

Program 1: Program to illustrate the working of exists() method

// Scala program to illustrate the working of exists() method 

import scala.collection.immutable.BitSet  

object MyObject{
    def main(args: Array[String]) {
        val Bitset = BitSet(45, 12, 69, 45, 9, 2, 17)
        
        if(Bitset.exists(x => {x % 5 == 0}))
            println("Element satisfies the given condition")
        else 
            println("No element satisfies the given condition")
    }
}

Output:

Element satisfies the given condition

Program 2: Program to illustrate the working of exists() method

// Scala program to illustrate the working of exists() method 

import scala.collection.immutable.BitSet  

object MyObject{
    def main(args: Array[String]) {
        val Bitset = BitSet(12, 69, 9, 2, 17)
        
        if(Bitset.exists(x => {x % 5 == 0}))
            println("Element satisfies the given condition")
        else 
            println("No element satisfies the given condition")
    }
}

Output:

No element satisfies the given condition





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.