Java BitSet clone() method

The clone() method of Java BitSet class is used to make the clone of this BitSet to new BitSet. The clone BitSet has equal to the current original BitSet. The clone bits are exactly the same true value as the original bit set.

Syntax:

Parameter:

NA

Returns:

The clone() method returns a new clone bit set of the current bit set.

Exception:

NA

Compatibility Version:

Java 1.0 and above

Example 1

Output:

Current bitset: {2, 3, 5, 6, 8}
Clone bitset: {2, 3, 5, 6, 8}

Example 2

Making clone of first BitSet to existing second BitSet replaces the existing bit sets of second BitSet with the first bit sets.

Output:

bitset1:{0, 1, 2, 3, 4}
bitset2:{5, 6, 7, 8, 9, 10, 11}
bitset1: {0, 1, 2, 3, 4}
bitset2 after cloning bitset1{0, 1, 2, 3, 4}