# Bitmap在Java中的实现和应用

>>40亿数据排序问题

### >>应用BitMap存储大数据

java.util.BitSet可以存true/false。

1，先找出数据中最大值maxvalue=9
2，声明一个BitSet bs,它的size是maxvalue+1=10
3，遍历数据source，bs[source[i]]设置成true.

(0为false;1为true)
bs [0,0,0,1,0,1,1,0,0,1]
3, 5,6, 9

### >>如何应用BitSet

BitSet实现了Vector接口，BitSet中数组大小会随需要增加，位的值为布尔型，
bitSet内部是通过一个long[]数组实现的，

This class implements a vector of bits that grows as needed.
BitSet类实现了一个按需增长的比特向量，
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.

Every bit set has a current size, which is the number of bits of space currently in use by the bit set. Note that the size is related to the implementation of a bit set, so it may change with implementation. The length of a bit set relates to logical length of a bit set and is defined independently of implementation.

 1 2 3 4 5 6 7 8 9 10 11 public static void main(String[] args) {         int [] array = new int [] {1,2,3,22,0,3};         BitSet bitSet  = new BitSet(6);         //将数组内容组bitmap         for(int i=0`;i

+ 订阅