Java basic learning notes 7 (3) -- Map interface

Source: Internet
Author: User

* ** Map <K, V> interface An object that maps keys to values. A map cannot contain
Duplicate keys; each key can map to at most one value.
Objects that map keys to values. A ing cannot contain duplicate keys. Each key can map only one value at most.
The keys in the map cannot be repeated, and hashCode is used for comparison. The effect is the same as that of equals,
It is faster to use hashCode.

Common Methods: 1. Object put (Object key, Object value)
Associates the specified value with the specified key in this map
Associate the specified value with the specified key in the ing.
Return Value: if the key in the map does not exist before, put it directly and return a null value,
If the key exists in the map, the new value replaces the old value and the value is returned.

2. Object get (Object key)
Returns the value to which the specified key is mapped.
Returns the value mapped to the specified key in the ing.

3. Object remove (Object key );
Removes the mapping for a key from this map if it is present
If the ing relationship of this key exists, remove it from the ing.

4. boolean containskey (Object key );
Returns true if this map contains a mapping for the specified key
Returns true if the ing contains the ing relationship of the specified key.

5. boolean containsValue (Object value)
Returns true if this map maps one or more keys to the specified value
Returns true if this ing maps one or more keys to a specified value.

6. int size ();
Returns the number of key-value mappings in this map
Returns the number of key-value ing relationships in the ing.

7. boolean isEmpty ()
Returns true if this map contains no key-value mappings.
Returns true if the ing does not contain a key-value ing relationship.

8. void putAll (Map map );
Copies all of the mappings from the specified map to this map
Copies all mappings from a specified ing to this ing (optional ).

9. void clear ();
Removes all of the mappings from this map.
Remove all mappings from this ing

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.