BitSet length() Method in Java with Examples Last Updated : 27 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The length() Method of BitSet class in Java is used to know the logical size of this BitSet. This logical size is equal to the highest bit of the BitSet plus one. Syntax: BitSet.hashCode() Parameters: The method does not accept any parameters. Return Value: The method returns the logical size of the BitSet which is equal to the highest bit of the set plus one. The method returns zero if the BitSet is empty. Below programs are used to illustrate the working of BitSet.length() Method: Program 1: Java // Java code to illustrate length() 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(31); init_bitset.set(100); init_bitset.set(53); // Displaying the BitSet System.out.println("BitSet: " + init_bitset); // Displaying the length or logical size System.out.println("The Length is: " + init_bitset.length()); } } Output: BitSet: {25, 31, 40, 53, 100} The Length is: 101 Program 2: Java // Java code to illustrate length() import java.util.*; public class BitSet_Demo { public static void main(String args[]) { // Creating an empty BitSet BitSet init_bitset = new BitSet(); // Displaying the BitSet System.out.println("BitSet: " + init_bitset); // Displaying the hashcode System.out.println("The Length is: " + init_bitset.length()); } } Output: BitSet: {} The Length is: 0 Comment More infoAdvertise with us Next Article BitSet length() 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 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 File length() method in Java with Examples The length() function is a part of File class in Java . This function returns the length of the file denoted by the this abstract pathname was length.The function returns long value which represents the number of bytes else returns 0L if the file does not exists or if an exception occurs. Function s 2 min read Year length() method in Java with Examples The length() method of Year class in Java is used to return the length of this year object's value in number of days. There can be only two possible lengths of Year, 365(Non-leap years) and 366(Leap years). Syntax: public int length() Parameter: This method does not accepts any parameter. Return Val 1 min read Byte longValue() method in Java with examples The longValue() method of Byte class is a built in method in Java which is used to return the value of this Byte object as long. Syntax ByteObject.longValue() Return Value: It return the value of ByteObject as long. Below is the implementation of longValue() method in Java: Example 1: Java // Java c 2 min read CharBuffer length() methods in Java with Examples The length() method of java.nio.CharBuffer Class is used to return the length of this character buffer. When viewed as a character sequence, the length of a character buffer is simply the number of characters between the position (inclusive) and the limit (exclusive); that is, it is equivalent to re 2 min read BitSet stream() Method in Java with Examples The stream() method of Java BitSet class is used to return a stream of indices for every bit contained in the BitSet. The indices are returned in increasing order. The size of the stream is the number of bits in the set state of the BitSet, which is equal to the value returned by the cardinality() m 2 min read BitSet hashCode Method in Java with Examples The hashCode() Method of BitSet class in Java is used to fetch the hash code value of a particular this BitSet. This returned hash codes value depends on the set bits of the bit set being passed. Syntax: BitSet.hashCode() Parameters: The method does not accept any parameters. Return Value: The metho 2 min read BitSet toString() Method in Java with Examples The java.util.BitSet.toString() is an inbuilt method of BitSet class that is used to get a string representation of the bits of the sets in the form of a set of entries separated by â, â. So basically the toString() method is used to convert all the elements of BitSet into String. In addition to thi 2 min read AtomicIntegerArray length() method in Java with Examples The Java.util.concurrent.atomic.AtomicIntegerArray.length() is an inbuilt method in Java that returns the length of the AtomicIntegerArray. This method does not accepts any parameter and returns the length of the AtomicIntegerArray which is of type int. Syntax: public final int length() Parameters: 2 min read Like