Operations on series of numbers : BitSet « Collections Data Structure « Java






Operations on series of numbers

  

import java.util.BitSet;

public class NumSeries {
  public static void main(String[] args) {
    for (int i = 1; i <= months.length; i++)
      System.out.println("Month # " + i);
  
    for (int i = 0; i < months.length; i++)
      System.out.println("Month " + months[i]);

    BitSet b = new BitSet();
    b.set(0);  // January
    b.set(3);  // April

    for (int i = 0; i<months.length; i++) {
      if (b.get(i))
        System.out.println("Month " + months[i] + " requested");
    }
  }
  /** The names of the months. See Dates/Times chapter for a better way */
  protected static String months[] = {
    "January", "February", "March", "April",
    "May", "June", "July", "August",
    "September", "October", "November", "December"
  };
}


           
         
    
  








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.BitOHoney
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.