在Java的文檔中說明了BitSet實現了Vector接口,是一個可按需增加的存儲位的數據結構,位的值位布爾型,初始大小爲64bit,初始值均爲「false」。數據結構
經常使用方法:code
void set(int bitIndex)、void set(int bitIntex, boolean value) : 將bitIndex位置的值設爲「true」或者給定的值對象
boolean get(int bitIndex) :獲取bitIndex位置處的值索引
BitSet get(int fromIndex, int toIndex) :以BitSet存儲返回fromIndex與toIndex區間之間的值接口
void clear()、void clear(int bitIndex)、void clear(int fromIndex, int toIndex) :置整個BitSet/相應位置/區間的值爲「false」ci
int length() :BitSet的邏輯大小(實際使用大小),值爲「true」最大的索引位加1文檔
int size() :BitSet的實際大小,默認爲64get
and(BitSet set)、andNot(BitSet set) … :與另外一BitSet相應的邏輯位運算it
String toString() :返回值爲「true」的位置的String對象,如第1和第10位爲「true」,其餘位置爲「false」,則返回{1, 10}方法