In this post, we will see BitSet Data Structure in Java Programming Language | BitSet in Java
Watch this video to know about BitSet Data Structure in Java:
Watch on YouTube: https://www.youtube.com/watch?v=YoFBNMMQrRA
Program Code: (BitSetProg.java)
Watch this video to know about BitSet Data Structure in Java:
Watch on YouTube: https://www.youtube.com/watch?v=YoFBNMMQrRA
Program Code: (BitSetProg.java)
import java.util.BitSet; public class BitSetProg { public static void main(String args[]) { BitSet b1 = new BitSet(10); BitSet b2 = new BitSet(10); // set bits based on divisible by 2 or 3 for(int i = 0; i < 10; i++) { if((i % 2) == 0) b1.set(i); if((i % 3) == 0) b2.set(i); } System.out.println("Values in b1: "); System.out.println(b1); System.out.println("Values in b2: "); System.out.println(b2); // AND method call b1.and(b2); System.out.println("b1 AND b2: "); System.out.println(b1); // OR method call b1.or(b2); System.out.println("b1 OR b2: "); System.out.println(b1); // XOR method call b1.xor(b2); System.out.println("b1 XOR b2: "); System.out.println(b1); } } |
Output:
parag@parag-Inspiron-N4010:~/Desktop/prog$ javac BitSetProg.java
parag@parag-Inspiron-N4010:~/Desktop/prog$ java BitSetProg Values in b1: {0, 2, 4, 6, 8} Values in b2: {0, 3, 6, 9} b1 AND b2: {0, 6} b1 OR b2: {0, 3, 6, 9} b1 XOR b2: {} |
No comments:
Post a Comment