There are two variants of get() in Bitset, both are discussed in this article. 1. boolean get( int value ) : Returns true if the value is present in Bitset, else returns false.
Declaration :
public boolean get(int value)
Parameters :
value : The value to check.
Return Value :
Returns boolean true, if element present else returns false.
Java
import java.util.*;
public class BitGet1 {
public static void main(String[] args)
{
BitSet bset = new BitSet( 5 );
bset.set( 0 );
bset.set( 1 );
bset.set( 2 );
bset.set( 4 );
System.out.println("Does 3 exist in Bitset? : " + bset.get( 3 ));
System.out.println("Does 4 exist in Bitset? : " + bset.get( 4 ));
}
}
|
Output :
Does 3 exist in Bitset? : false
Does 4 exist in Bitset? : true
2. Bitset get(int fromval, int toval) : method returns a new BitSet composed of elements present in Bitset from fromval (inclusive) to toval (exclusive).
Declaration :
public BitSet get(int fromval, int toval)
Parameters :
fromval : first value to include.
toval : last value to include(ex).
Return Value
This method returns a new BitSet from a range of this BitSet.
Java
import java.util.*;
public class BitGet2 {
public static void main(String[] args)
{
BitSet bset = new BitSet( 5 );
bset.set( 0 );
bset.set( 1 );
bset.set( 2 );
bset.set( 3 );
System.out.println("Values in BitSet from 0 - 2 are : " + bset.get( 0 , 3 ));
}
}
|
Output:
Values in BitSet from 0-2 are : {0, 1, 2}
If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Feeling lost in the vast world of Backend Development? It's time for a change! Join our
Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:
- Comprehensive Course
- Expert Guidance for Efficient Learning
- Hands-on Experience with Real-world Projects
- Proven Track Record with 100,000+ Successful Geeks
Last Updated :
03 May, 2022
Like Article
Save Article