6/1/2023 0 Comments Disassemble java hashtabImplementations, Hashtable is synchronized. Implement the Map interface, making it a member of the Therefore, it would be wrong to write a program that depended on thisĮxception for its correctness: the fail-fast behavior of iteratorsĪs of the Java 2 platform v1.2, this class was retrofitted to 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 Hashtable is structurally modified at any time after the enumeration isĬreated then the results of enumerating are undefined. The Enumerations returned by Hashtable's keys andĮlements methods are not fail-fast if the Modification, the iterator fails quickly and cleanly, rather than riskingĪrbitrary, non-deterministic behavior at an undetermined time in the future. Remove method, the iterator will throw a ConcurrentModificationException. Returned by all of this class's "collection view methods" areįail-fast: if the Hashtable is structurally modified at any timeĪfter the iterator is created, in any way except through the iterator's own The iterators returned by the iterator method of the collections To retrieve a number, use the following code: This example creates a hashtable of numbers. If many entries are to be made into a Hashtable,Ĭreating it with a sufficiently large capacity may allow theĮntries to be inserted more efficiently than letting it performĪutomatic rehashing as needed to grow the table. Setting the initial capacity too high can waste space. Hashtable will contain divided by its load factor. No rehash operations will ever occur if the initialĬapacity is greater than the maximum number of entries the Need for rehash operations, which are time-consuming. The initial capacity controls a tradeoff between wasted space and the Hashtable operations, including get and put). Increase the time cost to look up an entry (which is reflected in most Higher values decrease the space overhead but Generally, the default load factor (.75) offers a good tradeoff between Method is invoked are implementation-dependent. The exact details as to when and whether the rehash The initial capacity and load factor parameters are merely hints to Table is allowed to get before its capacity is automatically increased. The load factor is a measure of how full the hash Note that the hash table is open: in the case of a "hashĬollision", a single bucket stores multiple entries, which must be searched Initial capacity is simply the capacity at the time the hash table TheĬapacity is the number of buckets in the hash table, and the Performance: initial capacity and load factor. Objects used as keys must implement the hashCodeĪn instance of Hashtable has two parameters that affect its To successfully store and retrieve objects from a hashtable, the Non- null object can be used as a key or as a value. This class implements a hash table, which maps keys to values.
0 Comments
Leave a Reply. |