I have learned BitSet by farnetto's code.

source code

import java.util.Arrays;
import java.util.BitSet;

import org.junit.Test;

public class BitSetExample {
@Test
public void test() {
final int n = 10;
debug("2", getMultiple(n, 2));
debug("3", getMultiple(n, 3));
{
BitSet two = getMultiple(n, 2);
two.or(getMultiple(n, 3));
debug("or", two);
}
{
BitSet two = getMultiple(n, 2);
two.and(getMultiple(n, 3));
debug("and", two);
}
{
BitSet two = getMultiple(n, 2);
two.xor(getMultiple(n, 3));
debug("xor", two);
}
{
BitSet two = getMultiple(n, 2);
two.andNot(getMultiple(n, 3));
debug("andNot", two);
}
{
BitSet three = getMultiple(n, 3);
three.andNot(getMultiple(n, 2));
debug("andNot", three);
}
{
debug("intersects", getMultiple(n, 2).intersects(getMultiple(n, 3)));
}
{
debug("cardinality", getMultiple(n, 2).cardinality());
debug("cardinality", getMultiple(n, 3).cardinality());
}
}

private BitSet getMultiple(int n, int m) {
BitSet multiple = new BitSet();
for (int i = 1; i <= n; i++) {
if (i % m == 0) {
multiple.set(i);
}
}
return multiple;
}

private static final boolean DEBUG = true;

private static final void debug(Object... o) {
if (DEBUG)
System.err.println(Arrays.deepToString(o));
}

}