Java Collection Container Summary
first, according to the data structure mainly have the following categories : Built-in, list, set, map;
1. Built-in container: array
2. List Container :
Vetor,stack,arraylist,linkedlist,copyonwritearraylist (1.5), AttributeList (1.5), rolelist (1.5), roleunresolvedlist (1.5), Concurrentlinkedqueue (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).
Set Interface Inheritance Collection, but does not allow repetition, using one of its own internal arrangement mechanisms.
The List interface Inherits Collection, allowing repetition, placing elements in the order in which they are placed, and not rearranging them.
The map interface is a pair of key-value objects that hold some key-value pairs. There cannot be duplicate keys in the map. have their own internal arrangement mechanism .
second, according to the new and old mainly have the following categories :
Container before Java1.2: vector,stack,hashtable.
Java1.2 's container: Hashset,treeset,hashmap,treemap,weakhashmap
Containers for Java1.4:
Linkedhashset,linkedhashmap,identityhashmap,concurrentmap,concurrenthashmap
java1.5 added:
copyonwritearraylist,attributelist,rolelist,roleunresolvedlist,
Concurrentlinkedqueue,arrayblockingqueue,linkedblockingqueue,priorityblockingqueue
ArrayBlockingQueue , Copyonwritearrayset,enumset,
Unknown: jobstatereasons
three, by thread security mainly have the following categories :
1. Thread Safety
using locks : concurrency is not supported at all :
List container: Vetor,stack,copyonwritearraylist,arrayblockingqueue,
Linkedblockingqueue,priorityblockingqueue,synchronousqueue
Set Container: Copyonwritearrayset
Map container: Hashtable
using locks : partially supports concurrency :
List container: None
Set Container: None
Map container: Concurrenthashmap
using non-blocking algorithms :
List container: Concurrentlinkedqueue
Set Container: None
Map container: None
2. non-thread safe :
List container: Arraylist,linkedlist,attributelist,rolelist,roleunresolvedlist,priorityqueue
Set Container: Hashset,treeset,linkedhashset,enumset
Map container: Hashmap,treemap,linkedhashmap,weakhashmap,identityhashmap,enummap
four, according to traverse Security mainly have the following categories:
1.Traversal Security:
can traverse concurrently:
List container: Copyonwritearraylist,concurrentlinkedqueue
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, iterators are designed to be used by only one thread at a time.
2.traversal is not secure:
will throw an exceptionConcurrentmodificationexception:
List container: arraylist,linkedlist,attributelist,rolelist,roleunresolvedlist
Set Container: Hashset,treeset,treeset,linkedhashset
Map container: Hashmap,treemap,linkedhashmap,weakhashmap,identityhashmap
Note 1: The returned iterators are weakly consistent: they do not throw concurrentmodificationexception,
There is also a container that does not necessarily show the effect of any mapping modifications that occur when an iteration occurs:
Enumset,enummap
Five, according to traverse whether the order of classification
store data in order :
List container: Concurrentlinkedqueue (1.5), Arrayblockingqueue (1.5), Linkedblockingqueue (1.5),
Synchronousqueue (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).
stored data is ordered under certain rules :
List container:
Stack,vetor,arraylist,linkedlist,copyonwritearraylist (1.5), AttributeList (1.5), rolelist (1.5), roleunresolvedlist (1.5)
Set Container: None
Map container: None
Traverse unordered but remove order:
List container: Priorityqueue (1.5), Priorityblockingqueue (1.5)
Set Container: None
Map container: None
Anywayare 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)
It is possible to sort by natural order (see comparable) or comparator:
List container: Priorityqueue (1.5), Priorityblockingqueue
Set Container: TreeSet (1.2)
Map container: TreeMap (1.2)
the Randomaccess interface is implemented with:
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 primary purpose of this interface is to allow a generic algorithm to change its behavior so that it provides good performance when applied to random or contiguous access lists.
In the list-specific traversal algorithm, to try to determine whether it belongs to randomaccess (such as ArrayList) or sequenceaccess (such as LinkedList),
Because the randomaccess list is suitable for the traversal algorithm, used on the Sequenceaccess list on the difference is very large,
That is, for a class instance that implements the Randomaccess interface, this loop
for (int i=0, i<list.size (); i++)
List.get (i);
To run faster than the following loops:
For (Iterator i=list.iterator (); I.hasnext ();)
I.next ();
Java Collection Container Summary