
List
-
ArrayList
- permit
null. -
not synchronized.
List list = Collections.synchronizedList(new ArrayList(...)) -
an application can increase the capacity of an ArrayList instance before adding a large number of elements using the
ensureCapacityoperation.ensureCapacity(int minCapacity)
- permit
-
Vector
- synchronized.
-
Stack
- extends class
Vector. - a more complete and consistent set of LIFO stack operations is provided by the
Dequeinterface and its implementations.
- extends class
-
LinkedList
see also
Queue.
Map
-
Hashtable
- the keys must implement the hashCode method and the equals method.
- only non-null object can be used as a key or as a value.
-
synchronized.
Hashtable(int initialCapacity, float loadFactor=.75)
-
HashMap
- permits
nullvalues and thenullkey. -
not synchronized.
Map m = Collections.synchronizedMap(new HashMap(...))
- permits
-
LinkedHashMap
- permits
nullvalues and thenullkey. -
maintains a doubly-linked list running through all of its entries which defines the iteration ordering (insertion-order or access order which its entries were last accessed, from least-recently accessed to most-recently. This is well-suited to building LRU caches).
LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder) -
the
removeEldestEntry(Map.Entry)method may be overridden to impose a policy for removing stale mappings automatically when new mappings are added to the map.1234private static final int MAX_ENTRIES = 100;protected boolean (Map.Entry eldest) {return size() > MAX_ENTRIES;} -
not synchronized.
- permits
-
TreeMap
- the implementation based on Red-Black tree.
- permits
nullvalues. - sorted according to the natural ordering of its keys, or by a
Comparatorprovided at map creation time. - the ordering maintained by a sorted map must be consistent with
equalsif this sorted map is to correctly implement the Map interface. -
not synchronized.
SortedMap m = Collections.synchronizedSortedMap(new TreeMap(...))
-
ConcurrentHashMap
Queue
-
Queue
each of these methods exists in two forms: one throws an exception if the operation fails, the other returns a special value (
nullorfalse).Throws exception Returns special value Insert add(e) offer(e) Remove remove() poll() Examine element() peek() - Queue implementations generally do not allow insertion of
nullelements, although some implementations, such as LinkedList, but it should not be inserted into a Queue, as null is also used as a special return value by thepollmethod to indicate that the queue contains no elements.
- Queue implementations generally do not allow insertion of
-
PriorityQueue
-
based on a priority heap. Ordered according to their natural ordering, or by a
Comparatorprovided at queue construction time.public PriorityQueue(Comparator<? super E> comparator) - not synchronized.
-
-
Deque
each of these methods exists in two forms: one throws an exception if the operation fails, the other returns a special value (
nullorfalse).Head Tail Throws exception Returns special value Throws exception Returns special value Insert addFirst(e) offerFirst(e) addLast(e) offerLast(e) Remove removeFirst() pollFirst() removeLast() pollLast() Examine getFirst() peekFirst() getLast() peekLast() - this interface provides two methods to remove interior elements,
removeFirstOccurrenceandremoveLastOccurrence.
- this interface provides two methods to remove interior elements,
-
ArrayDeque
- resizable-array implementation of the
Dequeinterface. nullelements are prohibited.- not thread-safe.
- faster than
Stackwhen used as a stack, and faster thanLinkedListwhen used as a queue.
- resizable-array implementation of the
-
LinkedList
- doubly-linked list implementation of the
ListandDequeinterfaces. - permits all elements (including
null). -
not synchronized.
List list = Collections.synchronizedList(new LinkedList(...))
- doubly-linked list implementation of the
-
BlockingQueue
the third method blocks the current thread indefinitely until the operation can succeed, and the fourth blocks for only a given maximum time limit before giving up.
Throws exception Returns special value Blocks Times out Insert add(e) offer(e) put(e) offer(e, time, unit) Remove remove() poll() take() poll(time, unit) Examine element() peek() not applicable not applicable - does not accept
nullelements. - thread-safe.
- designed to be used primarily for producer-consumer queues.
- does not accept




近期评论