简体   繁体   中英

Insertion order in CopyOnWriteArraySet VS HashSet

Everyone knows HashSet stores elements in buckets based on the size of the hashtable and the elements' hash code values.

But how does CopyOnWriteArraySet store elements? I thought it makes a snapshot of those buckets and copies them. Looks like it doesn't. Does it store them in 'normal' array 1 by 1 and checks equals() ? Does it even use hashing principle?

CopyOnWriteArraySet is a Set -wrapper for CopyOnWriteArrayList , which stores its elements in an array, so it does not use hashing. That's why it doesn't have the O(1) lookup benefit of a HashSet.

The docs say it is only suitable for small sets.

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