Map interface Methods for Java

Source: Internet
Author: User
Tags set set

Common Operating Instructions

  void Clear ()

Removes all mapping relationships from this mapping (optional).

  Boolean ContainsKey (Object key)

Returns TRUE if this map contains a mapping relationship for the specified key.

  Boolean Containsvalue (Object value)

Returns true if the map maps one or more keys to the specified value.

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

Returns a Set view of the mapping relationships contained in this map.

  Boolean equals (Object O)

Compares whether the specified object is equal to this mapping.

  V get (Object key)

Returns the value mapped by the specified key, or null if the mapping does not contain a mapping relationship for the key.

  int Hashcode ()

Returns the hash code value for this mapping.

  Boolean IsEmpty ()

Returns true if the mapping does not contain a key-value mapping relationship.

  Set<k> KeySet ()

Returns a Set view of the keys contained in this map.

  V Put (K key, V value)

Associates the specified value with the specified key in this map (optional operation).

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

Copies all mappings from the specified map to this map (optional operation).

  V Remove (Object key)

If there is a mapping of a key, it is removed from this mapping (optional operation).

  int size ()

Returns the number of key-value mapping relationships in this map.

  Collection<v> VALUES ()

Returns a Collection view of the values contained in this map.

General usage of Map

1. Declare a map :

Map map = new HashMap ();

2 . Place values in map , Note: Map is stored in key-value form, such as:

Map.put ("sa", "DD");

3 . To take a value from the map :

String str = map.get ("sa"). ToString,

The result is: str = "DD"

4 . traverse a map to get the key and value from :

Map m= new HashMap ();

For (Object Obj:map.keySet ()) {

Object value = map.get (obj);

}

5 traverse the keyset in a map:

Map map = new HashMap ();
Map.put ("Key", "value");
Set set = Map.keyset ();
Iterator it = Set.iterator ();
Object object = It.next ();
Key
Object.ToString (); Value
Map.get (object);

Map interface Methods for Java

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.