BitOHoney : BitSet « Collections Data Structure « Java






BitOHoney

  

import java.util.BitSet;

public class BitOHoney1 {
  public static void main(String args[]) {
    String names[] = { "Hershey's Kisses", "Nestle's Crunch", "Snickers",
        "3 Musketeers", "Milky Way", "Twix", "Mr. Goodbar", "Crunchie",
        "Godiva", "Charleston Chew", "Cadbury's", "Lindt", "Aero",
        "Hebert", "Toberlone", "Smarties", "LifeSavers", "Riesen",
        "Goobers", "Raisenettes", "Nerds", "Tootsie Roll",
        "Sweet Tarts", "Cotton Candy" };
    BitSet bits = new BitSet();
    for (int i = 0, n = names.length; i < n; i++) {
      if ((names[i].length() % 2) == 0) {
        bits.set(i);
      }
    }
    System.out.println(bits);
    System.out.println("Size  : " + bits.size());
    System.out.println("Length: " + bits.length());
    for (int i = 0, n = names.length; i < n; i++) {
      if (!bits.get(i)) {
        System.out.println(names[i] + " is odd");
      }
    }
    BitSet bites = new BitSet();
    bites.set(0);
    bites.set(1);
    bites.set(2);
    bites.set(3);
    bites.andNot(bits);
    System.out.println(bites);
  }
}




           
         
    
  








Related examples in the same category

1.Java 1.5 (5.0) Changes to the API: several of the new bit manipulation methods in Integer.Java 1.5 (5.0) Changes to the API: several of the new bit manipulation methods in Integer.
2.The use of BitSetThe use of BitSet
3.Manipulating the BitSetManipulating the BitSet
4.Another Bitset demoAnother Bitset demo
5.Operations on series of numbers
6.BitOps
7.Convert bitset to int array and string
8.Implementation of a bit map of any size, together with static methods to manipulate int, byte and byte[] values as bit maps
9.Operations on bit-mapped fields.