1/9/2023 0 Comments Linked hashmap![]() Nested classes inherited from class java.util. Since: JDK1.4 Author: Josh Bloch See Also: Object.hashCode(), Therefore, it would be wrong to write a program that depended on thisĮxception for its correctness: the fail-fast behavior of iterators Throw ConcurrentModificationException on a best-effort basis. Presence of unsynchronized concurrent modification. Note that the fail-fast behavior of an iterator cannot be guaranteedĪs it is, generally speaking, impossible to make any hard guarantees in the Modification, the Iterator fails quickly and cleanly, rather than riskingĪrbitrary, non-deterministic behavior at an undetermined time in the The iterator is created, in any way except through the iterator's ownĬoncurrentModificationException. The iterators returned by the iterator methods of theĬollections returned by all of this class's collection view methods areįail-fast: if the map is structurally modified at any time after Merely querying the map with get is a structural The value associated with a key that is already contained in the map is notĪ structural modification. In insertion-ordered linked hash maps, merely changing Mappings or, in the case of access-ordered linked hash maps, affects Map m = Collections.synchronizedMap(new LinkedHashMap(.)) Ī structural modification is any operation that adds or deletes one or more Time, to prevent accidental unsynchronized access: If no such objectĮxists, the map should be "wrapped" using theĬollections.synchronizedMapmethod. On some object that naturally encapsulates the map. This is typically accomplished by synchronizing One of the threads modifies the map structurally, it must be Multiple threads access a linked hash map concurrently, and at least Note that this implementation is not synchronized. Than for HashMap, as iteration times for this class are unaffected Note, however, that the penalty for choosing anĮxcessively high value for initial capacity is less severe for this class They are defined preciselyĪs for HashMap. Is likely to be more expensive, requiring time proportional to itsĪ linked hash map has two parameters that affect its performance: Of a LinkedHashMap requires time proportional to the size Linked list, with one exception: Iteration over the collection-views Performance is likely to be just slightlyīelow that of HashMap, due to the added expense of maintaining the Remove), assuming the the hash function disperses elements Performance for the basic operations ( add, contains and This class provides all of the optional Map operations, and Impose a policy for removing stale mappings automatically when new mappings The removeEldestEntry(Map.Entry) method may be overridden to ![]() In particular, operations onĬollection-views do not affect the order of iteration of the backing Mappings are provided by the specified map's entry set iterator. The putAll method generates one entryĪccess for each mapping in the specified map, in the order that key-value Results in an access to the corresponding entry (assuming it exists after This kind of map is well-suited toīuilding LRU caches. ![]() In which its entries were last accessed, from least-recently accessed to Provided to create a linked hash map whose order of iteration is the order (Clients generally appreciate having things returned in the same This technique is particularly useful if a module takes a map on input,Ĭopies it, and later returns results whose order is determined by that of Original, regardless of the original map's implementation: ItĬan be used to produce a copy of a map that has the same order as the Without incurring the increased cost associated with TreeMap. This implementation spares its clients from the unspecified, generallyĬhaotic ordering provided by HashMap (and Hashtable), M.containsKey(k) would return true immediately prior to Reinserted into a map m if m.put(k, v) is invoked when Note that insertion order is not affected Which is normally the order in which keys were inserted into the map This linked list defines the iteration ordering, HashMap in that it maintains a doubly-linked list running throughĪll of its entries. Hash table and linked list implementation of the Map interface, Public class LinkedHashMap extends HashMap SUMMARY: NESTED | FIELD | CONSTR | METHODĬlass LinkedHashMap All Implemented Interfaces: Cloneable, Map, Serializable
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |