The map interface has a key and a value of one by one mappings. You can get the value by key.
- Given a key and a value, you can store the value in a Map object. After that, you can access the corresponding value by key.
- When the value of the access does not exist, the method throws a Nosuchelementexception exception.
- An classcastexception exception is thrown when the object's type is incompatible with the element type in the map.
- A NullPointerException exception is thrown when a null object is used in a map that does not allow the use of a null object.
- When attempting to modify a read-only map, a Unsupportedoperationexception exception is thrown.
|
Serial number |
Method description |
|
1 |
void Clear ()
Removes all mapping relationships from this mapping (optional). |
|
2 |
Boolean ContainsKey (Object k)
Returns TRUE if this map contains a mapping relationship for the specified key. |
|
3 |
Boolean containsvalue (Object v)
Returns true if the map maps one or more keys to the specified value. |
|
4 |
Set EntrySet ()
Returns a Set view of the mapping relationships contained in this map. |
|
5 |
Boolean equals (Object obj)
Compares whether the specified object is equal to this mapping. |
|
6 |
Object get (Object K)
Returns the value mapped by the specified key, or null if the mapping does not contain a mapping relationship for the key. |
|
7 |
int Hashcode ()
Returns the hash code value for this mapping. |
|
8 |
Boolean IsEmpty ()
Returns true if the mapping does not contain a key-value mapping relationship. |
|
9 |
Set KeySet ()
Returns a Set view of the keys contained in this map. |
|
10 |
Object put (object K, Object v)
Associates the specified value with the specified key in this map (optional operation). |
|
11 |
void Putall (Map m)
Copies all mappings from the specified map to this map (optional operation). |
|
12 |
Object Remove (object K)
If there is a mapping of a key, it is removed from this mapping (optional operation). |
|
13 |
int size ()
Returns the number of key-value mapping relationships in this map. |
|
14 |
Collection VALUES ()
Returns a Collection view of the values contained in this map. |
Map<string, object> m1 =NewHashmap<string, object>(); Map<string, object> m2 =NewHashmap<string, object>(); M1.put ("AAA", "BB"); M1.put ("AB", "CCCC"); M1.put ("DDD", "ddd"); SYSTEM.OUT.PRINTLN (M1); System.out.println ("------------1---------------"); System.out.println (M1.containskey ("AAA")); System.out.println (M1.entryset ()); System.out.println ("AAA". Equals (M1.containskey ("AAA"))); System.out.println ("BB". Equals (M1.get ("AAA")))); System.out.println (M1.get ("AAA"). Hashcode ()); System.out.println (M1.isempty ()); System.out.println (M1.keyset ()); M2.putall (M1); M2.put ("222", "222"); System.out.println (m2); M2.remove ("222"); M2.remove ("333"); System.out.println (m2); System.out.println (M2.size ()); System.out.println (M2.values ());
Execution Result:
{AAA=BB, ddd=ddd, ab=CCCC}------------1---------------true[AAA=BB, ddd=ddd, ab=CCCC ]falsetrue3136false[AAA, DDD, ab]{222=222, AAA=BB, ddd=ddd, ab=cccc}{ AAA=BB, ddd=ddd, ab=CCCC}3[BB, DDD, CCCC]
Java Map Interface