BitSet clone() Method in Java with Examples Last Updated : 27 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The clone() Method Java.util.BitSet class is used to create a copy of an existing BitSet. The new BitSet is exactly equal to the existing one and is a mere copy of the previous BitSet. Syntax: Bit_Set.clone() Parameters: The method does not take any parameters. Return Value: The method just returns another copy of the existing BitSet. Below programs illustrate the working of BitSet clone() method in Java. Program 1: Java // Java code to illustrate clone() import java.util.*; public class BitSet_Demo { public static void main(String args[]) { // Creating an empty BitSet BitSet init_bitset = new BitSet(); // Use set() method to add elements into the Set init_bitset.set(10); init_bitset.set(20); init_bitset.set(30); init_bitset.set(40); init_bitset.set(50); // Displaying the BitSet System.out.println("Initial BitSet: " + init_bitset); // Creating a new cloned set BitSet cloned_set = new BitSet(); // Cloning the set using clone() method cloned_set = (BitSet)init_bitset.clone(); // Displaying the new Set after Cloning System.out.println("The new BitSet: " + cloned_set); } } Output: Initial BitSet: {10, 20, 30, 40, 50} The new BitSet: {10, 20, 30, 40, 50} Program 2: Java // Java code to illustrate clone() import java.util.*; public class BitSet_Demo { public static void main(String args[]) { // Creating an empty BitSet BitSet init_bitset = new BitSet(); // Use set() method to add elements into the Set init_bitset.set(40); init_bitset.set(25); init_bitset.set(80); init_bitset.set(95); init_bitset.set(5); // Displaying the BitSet System.out.println("Initial BitSet: " + init_bitset); // Creating a new cloned set BitSet cloned_set = new BitSet(); // Cloning the set using clone() method cloned_set = (BitSet)init_bitset.clone(); // Displaying the new Set after Cloning System.out.println("The new BitSet: " + cloned_set); } } Output: Initial BitSet: {5, 25, 40, 80, 95} The new BitSet: {5, 25, 40, 80, 95} Comment More infoAdvertise with us Next Article BitSet clone() Method in Java with Examples chinmoy lenka Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-BitSet +1 More Practice Tags : JavaMisc Similar Reads ArrayList clone() method in Java with Examples The Java.util.ArrayList.clone() method is used to create a shallow copy of the mentioned array list. It just creates a copy of the list. Syntax: ArrayList.clone() Parameters: This method does not take any parameters. Return Value: This function returns a copy of the instance of Linked list. Below pr 2 min read Calendar clone() Method in Java with Examples The clear() method in Calendar class is used to clone a calendar object. It basically creates a shallow copy of this object. Syntax: public Object clone() Parameters: The method does not take any parameters. Return Value: The method does not return any value. Below programs illustrate the working of 2 min read BitSet size() Method in Java with Examples The size() Method of BitSet class in Java is used to know the size of this BitSet. This size is equal to the number of bits, each element has occupied in the BitSet. The maximum element in the set is the size - the first element Syntax: BitSet.hashCode() Parameters: The method does not accept any pa 2 min read Date clone() method in Java with Examples The clone() method of Date class in Java returns the duplicate of the passed Date object. This duplicate is just a shallow copy of the given Date object.Syntax: public Object clone() Parameters: The method does not accept any parameters.Return Value: The method returns a clone of the object.Below pr 2 min read BitSet class methods in Java with Examples | Set 3 BitSet class methods in Set 3. / / | | | \ \ and notand flip isEmpty equal get intersect BitSet class methods in Java with Examples | Set 2 BitSet class methods are explained as follows : and / notand : java.util.BitSet.and() and java.util.BitSet.notand() method is a java.util.Bitset class method. . 5 min read Like