To null), attempts to compute its value using the given mappingįunction and enters it into this map unless null. If the specified key is not already associated with a value (or is mapped 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 all of this class's "collection view methods"Īre fail-fast: if the map is structurally modified at any time after Map m = Collections.synchronizedMap(new HashMap(.)) This is best done at creation time, to prevent accidental If no such object exists, the map should be "wrapped" using the Synchronizing on some object that naturally encapsulates the map. Structural modification.) This is typically accomplished by That adds or deletes one or more mappings merely changing the valueĪssociated with a key that an instance already contains is not a (A structural modification is any operation The threads modifies the map structurally, it must be If multiple threads access a hash map concurrently, and at least one of Note that this implementation is not synchronized. To ameliorate impact, when keysĪre Comparable, this class may use comparison order among Many keys with the same hashCode() is a sure way to slowĭown performance of any hash table. The mappings to be stored more efficiently than letting it performĪutomatic rehashing as needed to grow the table. Instance, creating it with a sufficiently large capacity will allow If many mappings are to be stored in a HashMap Maximum number of entries divided by the load factor, no rehash If the initial capacity is greater than the Setting its initial capacity, so as to minimize the number of The map and its load factor should be taken into account when The operations of the HashMap class, including Space overhead but increase the lookup cost (reflected in most of Structures are rebuilt) so that the hash table has approximately twice theĪs a general rule, the default load factor (.75) offers a good When the number ofĮntries in the hash table exceeds the product of the load factor and theĬurrent capacity, the hash table is rehashed (that is, internal data Get before its capacity is automatically increased. Load factor is a measure of how full the hash table is allowed to TheĬapacity is the number of buckets in the hash table, and the initialĬapacity is simply the capacity at the time the hash table is created. Performance: initial capacity and load factor. Thus, it's very important not to set the initialĬapacity too high (or the load factor too low) if iteration performance isĪn instance of HashMap has two parameters that affect its HashMap instance (the number of buckets) plus its size (the number Iteration overĬollection views requires time proportional to the "capacity" of the Operations ( get and put), assuming the hash functionĭisperses the elements properly among the buckets. This implementation provides constant-time performance for the basic The order of the map in particular, it does not guarantee that the order Unsynchronized and permits nulls.) This class makes no guarantees as to (The HashMapĬlass is roughly equivalent to Hashtable, except that it is Implementation provides all of the optional map operations, and permits Hash table based implementation of the Map interface.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |