Home » Java » Java Map collection overview

Java Map collection overview

Java Map collection overview, there is a need for friends, you can refer to.

Map collection: the collection stores key value pairs. One to one to both. And to ensure the uniqueness of the key,.

1, add.

put (K, key, V, value)

putAll (Map<, extends, K, extends, V>, m)

2, delete.

clear ()

remove (Object key)

3, judge.

containsValue (Object value)

containsKey (Object key)

isEmpty ()

4, get.

get (Object key)

size ()

values ()

entrySet ()

keySet ()


The bottom layer of the |--Hashtable: is the hash table data structure, and cannot store the null key null value. The set is thread synchronous, and the.Jdk1.0. efficiency is low.

|--HashMap: the bottom layer is the hash table data structure that allows the use of the null value and the null key, which is not synchronized. Instead of hashtable, the jdk1.2. is efficient and.

|--TreeMap: the bottom layer is the two fork tree data structure. The thread is not synchronized. It can be used to sort keys in the map collection..

Like Set,.

, in fact, the bottom of the Set is the Map collection.

import java.util.*;
Class MapDemo
Public, static, void, main (String[], args)
Map, map = new, HashMap ();
/ / add elements, add elements, if there is added, the same key. Then add value will overwrite the existing keys corresponding value.
/ / and put method will return the overwritten value.
System.out.println ("put:", "+map.put" ("01", "zhangsan1"));
System.out.println ("put:", "+map.put" ("01", "wnagwu"));
Map.put ("02", "zhangsan2");
Map.put ("03", "zhangsan3");
System.out.println ("containsKey:", "+map.containsKey" ("022"));
//System.out.println ("remove:", "+map.remove" ("02"));
System.out.println ("get:", "+map.get" ("023"));
Map.put ("04", null);
System.out.println ("get:", "+map.get" ("04"));
/ / can judge whether a key is through get's return value. Judging by the return null.
For all values in the set / / map.
Collection coll = map.values ();
System.out.println (Coll);
System.out.println (map);

-- from "Bi 25 days >