Home » JAVA Programming » Collections » Question
  1. What is the output of this program?
     import java.util.*;
    public class Bitset_Example
    {
    public static void main(String args[])
    {
    BitSet object0 = new BitSet(12);
    BitSet object1 = new BitSet(15);
    for (int k = 0; k < 7; ++k)
    {
    object0.set(k);
    }
    for (int k = 3; k < 15; ++k)
    {
    object1.set(k);
    }
    object0.and(object1);
    System.out.print(object0);
    }
    }
    1. {3, 4, 5}
    2. {4, 5, 6}
    3. {4, 5}
    4. {3, 4, 5, 6}
    5. None of these
Correct Option: D

object0.and(object1) returns an BitSet object which contains elements common to both the object object0 and object1 and stores this BitSet in invoking object that is object0. Hence object0 contains {3, 4, 5, 6}.



Your comments will be displayed only after manual approval.