Example usage for java.util BitSet BitSet

List of usage examples for java.util BitSet BitSet

Introduction

In this page you can find the example usage for java.util BitSet BitSet.

Prototype

private BitSet(long[] words) 

Source Link

Document

Creates a bit set using words as the internal representation.

Usage

From source file:Main.java

public static void main(String[] args) {

    BitSet bitset1 = new BitSet(8);

    // assign values to bitset1
    bitset1.set(0);/*from w w  w  .j  av a  2 s  .  c o  m*/
    bitset1.set(1);
    bitset1.set(2);

    // print the sets
    System.out.println("Bitset1:" + bitset1.previousClearBit(1));
}

From source file:Main.java

public static void main(String[] args) {

    BitSet bitset1 = new BitSet(8);

    // assign values to bitset1
    bitset1.set(0);/*w  w w  . jav  a  2s  . com*/
    bitset1.set(1);
    bitset1.set(2);

    // print the sets
    System.out.println("Bitset1:" + bitset1.previousSetBit(1));
}

From source file:Main.java

public static void main(String[] args) {

    BitSet bitset1 = new BitSet(8);

    // assign values to bitset1
    bitset1.set(0);//  w  w w.jav a  2  s  . c o  m
    bitset1.set(1);
    bitset1.set(2);

    System.out.println(bitset1);

    bitset1.flip(1);

    System.out.println(bitset1);
}

From source file:Main.java

public static void main(String[] args) {

    BitSet bitset1 = new BitSet(8);

    bitset1.set(0);/*from w  w w .j av  a  2 s . c o  m*/
    bitset1.set(1);
    bitset1.set(2);

    BitSet bitset2 = new BitSet(8);

    bitset1.set(0);
    bitset1.set(1);
    bitset1.set(2);

    System.out.println(bitset1.equals(bitset2));

}

From source file:Main.java

public static void main(String[] args) {

    BitSet bitset1 = new BitSet(8);
    BitSet bitset2 = new BitSet(8);

    // assign values to bitset1
    bitset1.set(0);/*  w  w  w.j ava  2 s.c  om*/
    bitset1.set(1);
    bitset1.set(2);

    // assign values to bitset2
    bitset2.set(2);
    bitset2.set(4);
    bitset2.set(6);

    // print the sets
    System.out.println("Bitset1:" + bitset1);
    System.out.println("Bitset2:" + bitset2);

}

From source file:Main.java

public static void main(String[] args) {

    BitSet bitset1 = new BitSet(8);
    BitSet bitset2 = new BitSet(8);

    // assign values to bitset1
    bitset1.set(0);//ww w . jav a2s  .  co  m
    bitset1.set(1);
    bitset1.set(2);
    // assign values to bitset2
    bitset2.set(2);
    bitset2.set(4);
    bitset2.set(6);

    // print the sets
    System.out.println("Bitset1:" + bitset1);
    System.out.println("Bitset2:" + bitset2);

    // check if bitset1 intersects with bitset2
    System.out.println(bitset1.intersects(bitset2));

}

From source file:Main.java

public static void main(String[] args) {

    BitSet bitset1 = new BitSet(8);
    BitSet bitset2 = new BitSet(8);

    // assign values to bitset1
    bitset1.set(0);//from  w  w  w. ja v a  2s .  co m
    bitset1.set(1);
    bitset1.set(2);

    // assign values to bitset2
    bitset2.set(2);
    bitset2.set(4);

    // print the sets
    System.out.println("Bitset1:" + bitset1);
    System.out.println("Bitset2:" + bitset2);

    // print the size of the bitsets
    System.out.println(bitset1.size());
    System.out.println(bitset2.size());
}

From source file:Main.java

public static void main(String[] args) {

    BitSet bitset1 = new BitSet(8);
    BitSet bitset2 = new BitSet(8);

    // assign values to bitset1
    bitset1.set(0);/*from   ww w.  ja  v  a2 s .c  om*/
    bitset1.set(1);
    bitset1.set(2);

    // assign values to bitset2
    bitset2.set(2);
    bitset2.set(4);

    // print the sets
    System.out.println("Bitset1:" + bitset1);
    System.out.println("Bitset2:" + bitset2);

    // print the length of each bitset
    System.out.println(bitset1.length());
    System.out.println(bitset2.length());
}

From source file:Main.java

public static void main(String[] args) {

    BitSet bitset1 = new BitSet(8);
    BitSet bitset2 = new BitSet(8);

    // assign values to bitset1
    bitset1.set(0);/*from  w  w w .j a v  a 2s  .  c om*/
    bitset1.set(1);

    // assign values to bitset2
    bitset2.set(2);
    bitset2.set(4);
    bitset2.set(6);

    // print the sets
    System.out.println("Bitset1:" + bitset1);
    System.out.println("Bitset2:" + bitset2);

    // perform a logical or between the two bitsets
    bitset1.or(bitset2);
    System.out.println(bitset1);
}

From source file:Main.java

public static void main(String[] args) {

    BitSet bitset1 = new BitSet(8);
    BitSet bitset2 = new BitSet(8);

    // assign values to bitset1
    bitset1.set(0);//  ww w . java  2  s  .  co  m
    bitset1.set(1);

    // assign values to bitset2
    bitset2.set(2);
    bitset2.set(4);

    // print the sets
    System.out.println("Bitset1:" + bitset1);
    System.out.println("Bitset2:" + bitset2);

    // print the first set bit of bitset1
    System.out.println(bitset1.nextSetBit(0));

    // print the first set bit of bitset2 after index 5
    System.out.println(bitset2.nextSetBit(5));
}