toString() is an instance method of the BitSet class that returns the string representation of the BitSet object.
The string representation includes the decimal representation of every index for which the BitSet object has a bit in the set state.
These indices are given in ascending order, separated by ", " (a comma and a space), and enclosed by braces, similar to the standard mathematical notation for a collection of numbers.
The toString method is defined in the BitSet class. The BitSet class is defined in the java.util package. To import the BitSet class, use the following import statement.
import java.util.BitSet;
bitSet_Object.toString()
This method has no parameters.
This method returns the string representation of the object.
import java.util.BitSet;public class Main{public static void main(String[] args) {BitSet bitSet = new BitSet();bitSet.set(2);bitSet.set(3);bitSet.set(9);System.out.println("String representation = " + bitSet.toString());}}
BitSet class.BitSet object.2, 3, and 9.BitSet object.