Java Collection Framework-map interface __java

Source: Internet
Author: User
A map is a key value pair mapping object, a map cannot contain duplicate keys, and each key can uniquely map to at most one value.
This interface replaces the Dictonary class. The map interface provides three collection views that allow the contents of a map to be treated as a set of keys, a collection of values, or a collection of key-value mappings. The order of the map is defined as the order in which the iterator of the set view returns the sequence of its elements, and some implementations of the map interface, such as TREEMAP, ensure that the elements are ordered, others without this guarantee. When a mutable object is used as the key of a map, it is important to note that the map does not explicitly specify what to do when a key object that is a keyword sends a change and affects the return value of the Equals method. So try to avoid modifying the object as a key. All common map implementation classes should provide two constructors: parameterless constructs and constructors with only one map parameter that can be used to copy a map.

Some of the implementation classes of the map interface have restrictions on the key and value included, such as not allowing keys and value to be null, or some restrictions on the type of key. If you attempt to insert a data that does not meet the requirements in the map, you may throw a null pointer exception or a type conversion exception. If you attempt to query a nonexistent key or value in the map, you may throw an exception, or simply return a false.

Public interface Map<k,v> {
    //Query Operations

    int size ();

    Boolean IsEmpty ();

    Boolean ContainsKey (Object key);

    Boolean Containsvalue (Object value);

    V get (Object key);

    Modification Operations
    v put (K key, v value);

    V Remove (Object key);

    void Putall (map< extends K,? extends v> m);

    void Clear ();

    Set<k> keyset ();

    Collection<v> values ();

    Set<map.entry<k, v>> EntrySet ();

    Interface Entry<k,v> {
       
   K getkey ();
  
   V GetValue ();

   V SetValue (v value);

   Boolean equals (Object O);

   int hashcode ();
    }

    Comparison and hashing
    boolean equals (Object O);
 
    int hashcode ();
}

int Size ();

Returns the number of key value pairs in the map, and returns the maximum integer if the integer.max_value is exceeded.

Boolean IsEmpty ();

Returns true if there is no key value pair in the map

Boolean containskey (Object k);

Returns TRUE if the map contains a key-value pair for the specified key, that is, if it returns true, only one match can be made if and only if the map contains a key value pair that has a key of K.

boolean containsvalue (Object v);

Like ContainsKey, check that the map contains a key value pair mapping with a value of V, up to one.

V get (Object key);

Returns the value of the key in the key in map, or null if no mapping relationship exists for the key. More generally, it means that if the key value of the parameter key is mapped in the map (Key==null?k==null:key.equals (k)) then the value of the key is returned, or null is returned, which means If you have a map with a key that is null, it can also return the value of this null for you.

v put (K key, v value);

A mapping relationship between a key and a value is established in the map. If the map has previously had a mapping relationship with this key, the new put will overwrite the original. The realization of the implementation of the implementation of the class to see the operation.

V Remove (Object key); Putall (map< extends v>m); Putall (map< extends K,? extends V>m); Clear (); Don't do too much to repeat it.

set<k> keyset ();

Returns all the key in the map as set. A set is a structural component based on a map. The set set is associated with the map, and any action in the map is reflected in the set, and vice versa, if the value in the map is modified during the use of set, the consequences are undefined.

collection<v> values ();

Keyset returns a collection of keys in the map, and values returns a collection of value in the map. The returned collection is associated with the current map, the operations in the map are reflected in the collection, and vice versa; if the values in the map are modified during collection use, the consequences are not;

Set<map.entry<k,v>>entryset ();

Returns the set<map.entry<k,v>> of all mapping sets in the current map, and the same, associated with the map, the consequences of synchronization modifications are undefined, support for deletion does not support adding








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.