Java BitSet xor() method7 Jan 2025 | 2 min read The xor(BitSet set) method of Java BitSet class is used to perform a logical XOR operation on the set bits of this set with specified set argument. The value of bit set is modified so that each bit in it has true if and only if any one of the following statements satisfies:
Syntax:Parameter:
Returns:NA Exception:NullPointerException -If null parameter will pass in the method. Compatibility Version:Java 1.0 and above Example 1Output: bitset1: {0, 1, 4, 6, 7} bitset2: {2, 4, 6, 8, 10} xor operation between bitsets: {0, 1, 2, 7, 8, 10} Example 2This method throws a NullPointerException if we pass a null parameter. Output: Exception in thread "main" java.lang.NullPointerException at java.util.BitSet.xor(Unknown Source) at BitSetXorExample2.main(BitSetXorExample2.java:15) bitset1: {0, 1, 4, 6, 7} Next TopicJava-bitset-valueof-method |
The intersects(BitSet set) method of Java BitSet class returns Boolean value true or false on the basis of whether parameter BitSet has intersected with this BitSet or not. It returns true if the specified BitSet set is also true in this BitSet. Syntax: public boolean intersects(BitSet set) Parameter: DataType Parameter Description BitSet set It...
1 min read
The and() method of Java BitSet class is used to perform a logical AND operation of this target bit set with the specified set argument. The value of bit set is true if and only if the bit set of both initially and the corresponding...
2 min read
The clear() method of Java BitSet class is used to set the bits in the BitSet to false. There are various overloaded clear() methods available in BitSet class. 1. The clear() method set all the bits in the BitSet to false. 2. Java BitSet clear(int bitIndex) method The...
3 min read
The hashCode() method of Java BitSet class returns the hash code value of this BitSet. The value of hash code depends only on the bit which is set within this BitSet. Syntax: public int hashCode() Parameter: NA Returns: The hashCode() method returns the hash code value of this BitSet. Exception: NA Compatibility Version: Java 1.0...
1 min read
The toByteArray() method of Java BitSet class returns a new byte array which contains all of its bits. This method works on the basis of following algorithm: byte[] bytes = bitset.toByteArray(); then bytes.length == (bitset.length()+7)/8 and bitset.get(n) == ((bytes[n/8] & (1<<(n%8))) != 0) for all n <...
1 min read
The length() method of Java BitSet class returns the "logical size" of this BitSet. The length of BitSet goes up to the index of the highest set bit plus one. It returns zero if the BitSet does not contain any set bit. Syntax: public int length() Parameter: NA Returns: The length()...
1 min read
The andNot() method of Java BitSet class is used to clear the entire bit in this BitSet whose corresponding bit is set in the specified BitSet. Syntax: public void andNot(BitSet set) Parameter: DataType Parameter Description BitSet set It is a bit set. Returns: NA Exception: NullPointerException - If null parameter will pass in the method. Compatibility Version: Java 1.2 and...
2 min read
The flip() method of Java BitSet class sets the bit set to its complement. For example, if a bit value contains a true value then if you apply flip() operation on it, it will return false. There are two overloaded flip() method available in BitSet class....
2 min read
The get() method of Java BitSet class returns the bit value. There are two overloaded get() method available in BitSet class. 1. Java BitSet get(int bitIndex) method The get(int bitIndex) method returns the bit value of the specified index. It returns true if the index bitIndex is...
2 min read
The stream() method of Java BitSet class returns a stream of indices for which the current BitSet contains a bit. The return indices of bit are set to true value in the bit set and follow an increasing order. The size of stream refers to...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India