All Packages Class Hierarchy This Package Previous Next Index
Class java.util.ArrayMap
java.lang.Object
|
+----java.util.AbstractMap
|
+----java.util.ArrayMap
- public class ArrayMap
- extends AbstractMap
- implements Map, Cloneable, Serializable
This class implements the Map interface, backed by a ArrayList. It is
designed to offer good performance for very small Maps, especially those
that are frequently created and destroyed. The performance will be
extremely bad for large Maps: ArrayMap provides linear time
performance for the basic operations (get, put, remove, etc.). This Map
permits all keys and values, including null.
This class guarantees that the Map will be in key-insertion order.
If a new value is associated with a key already in the Map, the order
is unaffected. If a key-value mapping is removed and a mapping for
the same key is inserted at a later time, the mapping goes to the end of
the Map, just like any other key-insertion.
Note that this implementation is not synchronized. If
multiple threads access an ArrayMap concurrently, and at least one of the
threads modifies the ArrayMap structurally, it must be synchronized
externally. (A structural modification is any operation that adds or
deletes one or more mappings; merely changing the value associated
with a key that is already contained in the Table is not a structural
modification.) This is typically accomplished by synchronizing on some
object that naturally encapsulates the ArrayMap. If no such object exists,
the ArrayMap should be "wrapped" using the Collections.synchronizedSet
method. This is best done at creation time, to prevent accidental
unsynchronized access to the ArrayMap:
Map m = Collections.synchronizedMap(new ArrayMap(...));
The Iterators returned by the iterator methods of the Collections returned
by all of ArrayMap's "collection view methods" are fail-fast: if
the ArrayMap is structurally modified at any time after the Iterator is
created, in any way except through the Iterator's own remove or add methods,
the Iterator will throw a ConcurrentModificationException. Thus, in the
face of concurrent modification, the Iterator fails quickly and cleanly,
rather than risking arbitrary, non-deterministic behavior at an undetermined
time in the future.
- Since:
- JDK1.2
- See Also:
- Collection, Map, HashMap, TreeMap, Hashtable, Collections.synchronizedMap, ArrayList
ArrayMap()
- Constructs a new, empty ArrayMap; the backing ArrayList has default
initial capacity and capacity increment.
ArrayMap(int)
- Constructs a new, empty ArrayMap; the backing ArrayList has the
specified initial capacity and default capacity increment.
ArrayMap(Map)
- Constructs a new ArrayMap containing the mappings in the specified
Map.
clone()
- Creates a shallow copy of this ArrayMap.
entries()
- Returns a Collection view of the mappings contained in this ArrayMap.
put(Object, Object)
- Associates the specified value with the specified key in this Map
(optional operation).
ArrayMap
public ArrayMap()
- Constructs a new, empty ArrayMap; the backing ArrayList has default
initial capacity and capacity increment.
ArrayMap
public ArrayMap(Map t)
- Constructs a new ArrayMap containing the mappings in the specified
Map. The backing ArrayList has default initial capacity and
capacity increment.
- Throws:
NullPointerException
- the specified Map is null.
ArrayMap
public ArrayMap(int initialCapacity)
- Constructs a new, empty ArrayMap; the backing ArrayList has the
specified initial capacity and default capacity increment.
- Parameters:
- initialCapacity - the initial capacity of the ArrayList.
entries
public Collection entries()
- Returns a Collection view of the mappings contained in this ArrayMap.
Each element in the returned collection is a Map.Entry. The
Collection is backed by the ArrayMap, so changes to the ArrayMap are
reflected in the Collection, and vice-versa. The Collection supports
element removal, which removes the corresponding mapping from the
ArrayMap, via the Iterator.remove, Collection.remove, removeAll,
retainAll and clear operations. It does not support the add or
addAll operations.
- Overrides:
- entries in class AbstractMap
- See Also:
- Map.Entry
put
public Object put(Object key,
Object value)
- Associates the specified value with the specified key in this Map
(optional operation). If the Map previously contained a mapping for
this key, the old value is replaced.
- Parameters:
- key - key with which the specified value is to be associated.
- value - value to be associated with the specified key.
- Returns:
- previous value associated with specified key, or null if there
was no entry for key. (A null return can also indicate that
the Map previously associated null with the specified key.)
- Overrides:
- put in class AbstractMap
clone
public Object clone()
- Creates a shallow copy of this ArrayMap. The keys and values
themselves are not cloned.
- Overrides:
- clone in class Object
All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature