BitSet clone() in Java

clone(): This method is available in java.util.BitSet class of Java.

Syntax:

Object java.util.BitSet.clone()

This method of cloning this BitSet produces a new BitSet that is equal to it.

Parameters: NA

Returns: a clone of this bit set.

Exceptions: NA

Approach

Java

import java.util.BitSet;

public class BitSetclone {
    public static void main(String[] args) {
        BitSet bitSet = new BitSet(20);

        bitSet.set(1);

        bitSet.set(5);
        bitSet.set(6);
        bitSet.set(10);
        System.out.println(bitSet.clone());
    }
}

Output:

{1, 5, 6, 10}


No comments:

Post a Comment