Converts a boolean array into a BitSet - Java java.lang

Java examples for java.lang:boolean

Description

Converts a boolean array into a BitSet

Demo Code


//package com.java2s;

import java.util.BitSet;

public class Main {
    /**/*from w  w w . ja  v a2 s  .  com*/
     * Converts a boolean array into a BitSet
     * @param bits Boolean array to convert.
     * @param offset Array index to start reading from.
     * @param length Number of bits to convert.
     * @return 
     */
    public static BitSet boolToBitSet(boolean[] bits, int offset, int length) {
        BitSet bitset = new BitSet(length - offset);
        for (int i = offset; i < length; i++)
            bitset.set(i - offset, bits[i]);

        return bitset;
    }
}

Related Tutorials