toLongArray()
is an instance method of the BitSet
, which is used to return the long
array that has all the bits in the BitSet
object.
bitset
classThe toLongArray
method is defined in the BitSet
class. The BitSet
class is defined in the java.util
package. To import the BitSet
class, check the following import statement.
import java.util.BitSet;
Let’s view the syntax of the method.
public long[] toLongArray()
This method has no parameters.
This method returns a long array.
Let’s run an example that shows the working of the function:
import java.util.Arrays;import java.util.BitSet;public class Main{public static void main(String[] args) {// Create empty BitSet objectBitSet bitSet = new BitSet();// Set the bit at index 2bitSet.set(2);// Get the long array of the Bitset object using the toLongArray()System.out.printf("%s.toLongArray() = %s" , bitSet, Arrays.toString(bitSet.toLongArray()));}}