简体   繁体   中英

How BitSet admit long array with length 6?

BitSet internally uses long array of size 6.

But it can contain 2^31-1 bits.

long = 64 bit

6 longs = 64 * 6. But is much less than 2^31-1. Please explain this trick.

The internal array which stores the values expands if necessary, just like an ArrayList would do for objects. Your statement is therefore false.

There is a hard limit of 2^31-1 (bits) for the size, but that's only because the operations ( set , flip , etc.) take the index parameter as an int . Which is probably big enough for most use cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM