Key-value mapping for Java record -63-java map

Source: Internet
Author: User

public interface map<k,v>

The object that maps the key to a value. A map cannot contain duplicate keys, and each key can be mapped to at most one value.

The map interface replaces the Dictionary class, which is completely an abstract class, not an interface.

The map interface provides three collection views that allow you to view the contents of a map in the form of a keyset, value set, or key - value mapping relationship set. The mapping order is defined as the order in which iterators return their elements on the mapped collection view. Some mapping implementations can explicitly guarantee their order, such as the TreeMap class, while others do not guarantee the order, such as the HashMap class.

Map has a nested class:

public static Interface Map.entry<k,v>

Mapping Entries (key - value pairs). The Map.entryset method returns the collection view of the map, where the elements belong to this class. The only way to get a mapping item reference is through an iterator to this collection view. These map.entry objects are valid only during the iteration, or, more specifically, if the underlying mappings are modified after an iterator returns an item, the behavior of some of the mapping entries is indeterminate, in addition to performing operations on the mapping item by SetValue .

Public class Hashmap<k,v> extends abstractmap<k,v> implements Map<k,v>, Cloneable, Serializabl e

The implementation of a hash table-based Map interface. This implementation provides all the optional mapping operations and allows null values and null keys to be used. (TheHashMap class is roughly the same as Hashtable except for non-synchronous and null -allowed use.) This class does not guarantee the order of the mappings, especially because it does not guarantee that the order is constant.

This implementation assumes that the hash function distributes elements appropriately between buckets, providing stable performance for basic operations (get and put). The time required to iterate the collection view is proportional to the capacity of the HashMap instance (the number of buckets) and its size (number of key - value mappings). Therefore, if iteration performance is important, do not set the initial capacity too high (or set the load factor too low).

An instance of HashMap has two parameters that affect its performance: initial capacity and load factor. Capacity is the number of buckets in the hash table, and the initial capacity is just the capacity at the time of creation of the Hashtable. A load factor is a scale in which a hash table can reach a full amount before its capacity increases automatically. When the number of entries in the hash table exceeds the product of the load factor with the current capacity, the Hashtable is rehash (that is, rebuilding the internal data structure) so that the Hashtable will have about twice times the number of buckets.


Public class Treemap<k,v> extends abstractmap<k,v> implements Navigablemap<k,v>, Cloneable, Serializable

Based on the navigablemap of the red and black trees (red-black tree). The mapping is sorted according to the natural order of its keys, or sorted based on the Comparator provided when the mapping was created, depending on the construction method used.


Key-value mapping for Java record -63-java map

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.