Java Collection container summary.
There are mainly the following types of data structures::
1. built-in container: Array
2. List container: Vetor, stack, arraylist, role list,
Copyonwritearraylist (1.5), attributelist (1.5), rolelist (1.5), roleunresolvedlist (1.5 ),
Concurrentincluqueue (1.5), arrayblockingqueue (1.5), linkedblockingqueue (1.5 ),
Priorityqueue (1.5), priorityblockingqueue (1.5), synchronousqueue (1.5)
3. Set container: Hashset (1.2), linkedhashset (1.4), treeset (1.2 ),
Copyonwritearrayset (1.5), enumset (1.5), jobstatereasons.
4. Map container: Hashtable, hashmap (1.2), treemap (1.2), linkedhashmap (1.4), weakhashmap (1.2 ),
Identityhashmap (1.4), concurrentmap (1.5), concurrenthashmap (1.5 ).
The Set interface inherits collections, but it cannot be repeated. It uses an internal arrangement mechanism.
The list interface inherits collections and allows repeated elements. elements are placed in the order of element inserts without being rearranged.
The map interface is a key-value object consisting of a pair. Duplicate keys are not allowed in map. Internal Arrangement Mechanism.
There are mainly the following types based on the new and old:
Containers before Java: vector, stack, and hashtable.
Java1.2 containers: hashset, treeset, hashmap, treemap, weakhashmap
Java1.4 containers: linkedhashset, linkedhashmap, identityhashmap, concurrentmap, concurrenthashmap
Java1.5 added: copyonwritearraylist, attributelist, rolelist, roleunresolvedlist,
Concurrentlinkedqueue, arrayblockingqueue, linkedblockingqueue, priorityblockingqueue
Arrayblockingqueue, copyonwritearrayset, enumset,
Unknown: jobstatereasons
Thread-based security mainly includes the following types::
Thread Security
I,Use lock:
1.1,Concurrency is not supported at all.:
List container: vetor, stack, copyonwritearraylist, arrayblockingqueue,
Linkedblockingqueue, priorityblockingqueue, synchronousqueue
Set container: copyonwritearrayset
Map container: hashtable
Partially supports concurrency:
List container: None
Set container: None
Map container: concurrenthashmap
2.2,Use non-Blocking Algorithms:
List container: concurrent1_queue
Set container: None
Map container: None
II,Non-thread security:
List container: arraylist, rule list, attributelist, rolelist, roleunresolvedlist, priorityqueue
Set container: hashset, treeset, linkedhashset, enumset
Map container: hashmap, treemap, linkedhashmap, weakhashmap, identityhashmap, enummap
Traversal security mainly includes the following types::
I,Traversal Security:
Concurrent Traversal:
List container: copyonwritearraylist, concurrent1_queue
Set container: copyonwritearrayset, enumset, enummap
Map container: None
Non-concurrent Traversal:
List container: vetor, stack, hashtable, arrayblockingqueue,
Linkedblockingqueue, priorityblockingqueue, synchronousqueue
Set container: None
Map container: hashtable, concurrenthashmap
Note 1: concurrenthashmap iterators do not throw concurrentmodificationexception. However, the iterator is designed to be used by only one thread at a time.
II,Insecure Traversal:
Exception thrownConcurrentmodificationexception:
List container: arraylist, rule list, attributelist, rolelist, roleunresolvedlist
Set container: hashset, treeset, treeset, and linkedhashset
Map container: hashmap, treemap, linkedhashmap, weakhashmap, identityhashmap
Note 1 : Enumset, Which Is Weakly Consistent with the iterator returned by enummap: they do not throw concurrentmodificationexception,It does not necessarily display any ing modifications that occur during iteration.
Sort by order or not
Simple and orderly data storage :
List container: concurrent1_queue (1.5), arrayblockingqueue (1.5), linkedblockingqueue (1.5 ),
Synchronousqueue (0, 1.5)
Set container: treeset (1.2). (they implement the set Interface ),
Copyonwritearrayset (1.5), enumset (1.5), jobstatereasons.
Map container: treemap (1.2), linkedhashmap (1.4 ).
The stored data has a specific sequence. :
List containers: Stack, vetor, arraylist, rule list, copyonwritearraylist (1.5), attributelist (1.5), rolelist (1.5), roleunresolvedlist (1.5)
Set container: None
Map container: None
Traverse unordered but remove ordered :
List container: priorityqueue (1.5), priorityblockingqueue (1.5)
Set container: None
Map container: None
Whatever Unordered :
List container: None
Set container: hashset (1.2), linkedhashset (1.4)
Map container: hashtable, hashmap (1.2), weakhashmap (1.2), identityhashmap (1.4 ),
Concurrentmap (1.5), concurrenthashmap (1.5)
Which can be sorted in the natural order (see comparable) or by the comparator? :
List container: priorityqueue (1.5), priorityblockingqueue
Set container: treeset (1.2)
Map container: treemap (1.2)
Implemented the randomaccess Interface :
Arraylist, attributelist, copyonwritearraylist, rolelist, roleunresolvedlist, stack, Vector
The randomaccess interface is the tag interface used by the list implementation to indicate that it supports fast (usually fixed-time) random access. The main purpose of this interface is to allow general algorithms to change their behavior, so as to provide good performance when applying it to random or continuous access lists.
In the Special List traversal algorithm, we should try to judge whether it belongs to randomaccess (such as arraylist) or sequenceaccess (such as sort list ),
Because it is suitable for the traversal algorithm of randomaccess list, it is very different in sequenceaccess list,
That is, for a class instance that implements the randomaccess interface, this loop
For (INT I = 0, I <list. Size (); I ++)
List. Get (I );
Is faster than the following cycle:
For (iterator I = List. iterator (); I. hasnext ();)
I. Next ();
For more details about the randomaccess interface, refer 《
Random Access to randomaccess"
Capacity cannot be automatically expanded:
Arrayblockingqueue