0

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

2
  • You can check java docs before asking. Commented Nov 29, 2013 at 8:33
  • 2
    What do you mean "binary array"? Commented Nov 29, 2013 at 8:51

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.