Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

Is there already a specific method for converting a Boolean array to a binary array or would I just need a for loop?

share|improve this question

marked as duplicate by R.J, Dennis Meng, LaurentG, Jim Garrison, Stephane Delcroix Nov 30 '13 at 8:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
You can check java docs before asking. –  Foolish Nov 29 '13 at 8:33
2  
What do you mean "binary array"? –  Bohemian Nov 29 '13 at 8:51

1 Answer 1

If you want to serialize boolean array, check this: How to convert boolean array to binary and vice versa in Java?

If you want to use bits instead of booleans, check BitSet class: http://docs.oracle.com/javase/7/docs/api/java/util/BitSet.html

This class implements a vector of bits that grows as needed. Each component of the bit set has a boolean value. The bits of a BitSet are indexed by nonnegative integers. Individual indexed bits can be examined, set, or cleared. One BitSet may be used to modify the contents of another BitSet through logical AND, logical inclusive OR, and logical exclusive OR operations.

By default, all bits in the set initially have the value false.

You can use these methods:

BitSet#set(int) to set the bit to true at specified position.
BitSet#clear(int) to set the bit to false at specified position.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.