Presents your JAVA E-NEWSLETTER for July 8, 2002 -------------------------------------------- MANAGE A SERIES OF OPTIONS WITH THE BITSET CLASS If you want to emulate the C programming style of storing many boolean values in a single variable, use the java.util.BitSet class rather than compiling them into a primitive 'long' variable. The BitSet class is useful for managing a series of options in a concise and low-memory way. It provides a way to store N bits into a generic object. The class itself must decide how much memory it should use and when to change strategies. All the developer has to worry about is which bits to set. Bits are automatically turned off until they are set. Here's how to create a BitSet: // for the value '01001' BitSet bits = new BitSet( ); bits.set(1); bits.set(4); It's possible to automatically output a BitSet by using the toString method. The output data will resemble the following: {1, 4} You can also use a method that shows the output as the binary, such as: static public String output(BitSet bits) { int size = bits.length( ); StringBuffer buffer = new StringBuffer( ); for(int i=0; i