Sie sind auf Seite 1von 10

http://tutorials.jenkov.com/java-collections/index.

html
List
ArrayList
LinkedList

Vector

Stack

Set
EnumSet

It represents an ordered list of objects, me


The ArrayList class extends AbstractList and im

Represents a doubly linked list.Operations that index into t


Synchronization:if one thread is working on Vector, no other thread ca
Resize: ArrayList grow by half of its size when resized while Vector do
Performance: ArrayList gives better performance as it is non-synchro
fail-fast: Vector is not fail-fast
The Stack class represents a last-in-first-out (LIFO)
push() - To put an object on the top of the stack
pop() - To remove and return the top element
peek( ) - to return, but not remove, the top object.

represents set of o
A specia

HashSet

This class implements the Set interface, backed by a hash table (actu
guarant

LinkedHashSet

The java.util.LinkedHashSet class is a Hash table and Linked list imple


Following are the important points about LinkedHashSet:This class p

The java.util.NavigableSet interface is a subtype of the java.util.Sorte


addition to the sorting mechanisms of the SortedSet
In Java 6 there is only one implementation of the NavigableSet interfa
NavigableSet

SortedSet

TreeSet

descendingIterator() and descendingSet() - Sorting


headSet(), tailSet() and subSet() - less than, higher than, between
ceiling(), floor(), higher(), and lower() - smallest,highest,smallest than
pollFirst() and pollLast() - returns and removes

It behaves like a normal set with the exception that the e

The java.util.TreeSet class implements the Set interface.Following are


The TreeSet class guarantees that the Map will be in ascending key
The Map is sorted according to the natural sort method for the key
The ordering must be total in order for the Tree to function properly

interface

Map
HashMap
Hashtable
EnumMap

IdentityHashMap
LinkedHashMap
TreeMap

HashMap maps a key and a value. I

Hash
Hashtable does not allow null key

A specialize

This class implements the Map interface with a hash table, usin
IdentityHashMap, two keys k1 and k2 are considered equal if and onl
on
This implementation differs from Has
TreeMap also maps a key and a value. Furthermore it guar

The java.util.WeakHashMap class is a hashtable-based Map impleme


WeakHashMap

SortedMap

The java.util.SortedMap interface is a subtype of the jav


has one implementa

It has a few extensions


has one implem

descendingKeySet() - returns a NavigableS


descendingMap() headMap(), ta
ceiling(), floor(), high
celingEntry(), flo
pollFirst
NavigableMap
Queue
LinkedList
PriorityQueue
Deque
LinkedList
ArrayDeque

A queue is designed to have elements inser

Linked
PriorityQueue stores its elements internally according to their n

A queue is designed to have elements inser


LinkedList

ArrayDeque stores its elements internally in an array. If the number


words, the ArrayDeq

rdered list of objects, meaning you can access the elements of a List in a specific order, and by an index too
ends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed

erations that index into the list will traverse the list from the beginning or the end, whichever is closer to the spe
Vector, no other thread can get a hold of it.
n resized while Vector doubles the size of itself by default when grows.
ance as it is non-synchronized.

(LIFO)
ack
t
bject.
represents set of objects, meaning each element can only exists once in a Set
A specialized Set implementation for use with enum types

ked by a hash table (actually a HashMap instance). It makes no guarantees as to the iteration order of the set; i
guarantee that the order will remain constant over time.

able and Linked list implementation of the Set interface, with predictable iteration order.
nkedHashSet:This class provides all of the optional Set operations, and permits null elements.

ype of the java.util.SortedSet interface. It behaves like a SortedSet with the exception you have navigation met
rtedSet
the NavigableSet interface in the java.util package: java.util.TreeSet

orting
higher than, between
est,highest,smallest than, highest than
es

the exception that the elements are sorted internally. one implementation of the SortedSet interface - the java.

et interface.Following are the important points about TreeSet:


will be in ascending key order and backed by a TreeMap.
sort method for the key Class, or by the Comparator provided at set creation time, that will depend on which co
Tree to function properly.

interface represents a mapping between a key and a value.


Add - put()
Key Iterator - keySet()
Value iterator - values()

maps a key and a value. It does not guarantee any order of the elements stored internally in the map.

Hashtable is synchronized, whereas HashMap is not


le does not allow null keys or values. HashMap allows one null key and any number of null values.
A specialized Map implementation for use with enum type keys

ce with a hash table, using reference-equality in place of object-equality when comparing keys (and values). In o
nsidered equal if and only if (k1==k2). (In normal Map implementations (like HashMap) two keys k1 and k2 are
only if (k1==null ? k2==null : k1.equals(k2)).)
entation differs from HashMap in that it maintains a doubly-linked list running through all of its entries.
alue. Furthermore it guarantees the order in which keys or values are iterated - which is the sort order of the ke

able-based Map implementation with weak keys. An entry in a WeakHashMap will automatically be removed by
when its key is no longer in use

ce is a subtype of the java.util.Map interface, with the addition that the elements stored in the map are sorted i
has one implementation of the SortedMap interface - the java.util.TreeMap class.
It has a few extensions to the SortedSet which makes it possible to navigate the map.
has one implementation of the NavigableMap interface: java.util.TreeMap

t() - returns a NavigableSet in which the order of the elements is reversed compared to the original key set.
descendingMap() - returns a NavigableMap which is a view of the original Map.
headMap(), tailMap() and subMap() - less than,higher than,between
ceiling(), floor(), higher(), and lower() - smallest,highest,smallest than, highest than
celingEntry(), floorEntry(), higherEntry(), lowerEntry() - returns Map.Entry
pollFirstEntry() and pollLastEntry() - returns and removes

d to have elements inserted at the end of the queue, and elements removed from the beginning of the queue

LinkedList is a pretty standard queue implementation


nally according to their natural order (if they implement Comparable), or according to a Comparator passed to t

d to have elements inserted at the end of the queue, and elements removed from the beginning of the queue
LinkedList is a pretty standard deque / queue implementation.

n an array. If the number of elements exceeds the space in the array, a new array is allocated, and all elements
words, the ArrayDeque grows as needed, even if it stores its elements in an array.

ecific order, and by an index too


mic arrays that can grow as needed.

e end, whichever is closer to the specified index.

in a Set

as to the iteration order of the set; in particular, it does not

ration order.
mits null elements.

exception you have navigation methods available in

f the SortedSet interface - the java.util.TreeSet

n time, that will depend on which constructor used.

red internally in the map.

number of null values.

n comparing keys (and values). In other words, in an


HashMap) two keys k1 and k2 are considered equal if and

g through all of its entries.


d - which is the sort order of the keys or values

p will automatically be removed by the garbage collector,

ments stored in the map are sorted internally.


ap class.

te the map.
eMap

ompared to the original key set.


nal Map.
en
ghest than
.Entry

from the beginning of the queue

ording to a Comparator passed to the PriorityQueue.


from the beginning of the queue

array is allocated, and all elements moved over. In other


n an array.

fail-fast:If the collection (ArrayList, vector etc) gets structurally modified by any means, except the ad
iterator, after creation of iterator then the iterator will throw ConcurrentModificationException. Structu
the addition or deletion of elements from the collection.

Das könnte Ihnen auch gefallen