Home »
Java programming language
Java BitSet length() Method with Example
BitSet Class length() method: Here, we are going to learn about the length() method of BitSet Class with its syntax and example.
Submitted by Preeti Jain, on January 22, 2020
BitSet Class length() method
Syntax:
public int length();
Parameter(s):
- It does not accept any parameter.
Return value:
The return type of this method is int, it returns the size of this BitSet in integer.
Example:
// Java program to demonstrate the example
// of int length() method of BitSet.
import java.util.*;
public class LengthOfBitSet {
public static void main(String[] args) {
// create an object of BitSet
BitSet bs = new BitSet(10);
// By using set() method is to set
// the values in BitSet
bs.set(10);
bs.set(20);
bs.set(30);
bs.set(40);
bs.set(50);
// Display Bitset
System.out.println("bs: " + bs);
// By using length() method is to return
// the length of this BitSet
int len = bs.length();
// Display length of bs
System.out.println("bs.length(): " + len);
}
}
Output
bs: {10, 20, 30, 40, 50}
bs.length(): 51