Commonalities: HashMap, LinkedHashMap, and TreeMap all belong to Map. Map is mainly used to store key-value pairs and obtain values based on keys. Therefore, duplicate keys are not allowed, the allowed values are repeated. Differences: 1. the key-value pairs stored in HashMap are random during retrieval, which is also our most commonly used Map. it stores data based on the HashCode value of the key, and can directly obtain its value based on the key, with fast access speed. HashMap is the best choice for inserting, deleting, and locating elements in a Map. 2. TreeMap obtains the sorted key-value pairs. However, if you want to traverse keys in the natural or custom order, it is better to use TreeMap. 3. linkedHashMap is a subclass of HashMap. If the output sequence is the same as that of the input, you can use LinkedHashMap. (Application Scenario: shopping cart, etc.) code example: [java] package com. alibaba. sample. petstore. web. store. module. screen; import java. util. hashMap; import java. util. iterator; import java. util. linkedHashMap; import java. util. map; import java. util. map. entry; import java. util. treeMap; import javax. servlet. http. httpServletResponse; import org. springframework. beans. factory. annotation. autowired; public class ViewCart {@ Autowired private HttpServletResponse response; public void execute () throws Exception {this. useHashMap (); this. useTreeMap (); this. useLikedHashMap ();} public void useHashMap () throws Exception {response. getWriter (). println ("------ unordered (random output) ------"); Map <String, String> map = new HashMap <String, String> (); map. put ("1", "Level 1"); map. put ("2", "Level 2"); map. put ("3", "Level 3"); map. put ("a", "Level a"); map. put ("B", "Level B"); map. put ("c", "Level c"); Iterator <Entry <String, String> it = map. entrySet (). iterator (); while (it. hasNext () {Entry <String, String> e = it. next (); response. getWriter (). println ("Key:" + e. getKey () + "; Value:" + e. getValue () ;}// ordered (default sorting, cannot be specified) public void useTreeMap () throws Exception {response. getWriter (). println ("------ ordered (but not specified by default) ------"); Map <String, String> map = new TreeMap <String, String> (); map. put ("1", "Level 1"); map. put ("2", "Level 2"); map. put ("3", "Level 3"); map. put ("a", "Level a"); map. put ("B", "Level B"); map. put ("c", "Level c"); Iterator <Entry <String, String> it = map. entrySet (). iterator (); while (it. hasNext () {Entry <String, String> e = it. next (); response. getWriter (). println ("Key:" + e. getKey () + "; Value:" + e. getValue () ;}} public void useLikedHashMap () throws Exception {response. getWriter (). println ("------ ordered (output according to the input order) ------"); Map <String, String> map = new LinkedHashMap <String, String> (); map. put ("1", "Level 1"); map. put ("2", "Level 2"); map. put ("3", "Level 3"); map. put ("a", "Level a"); map. put ("B", "Level B"); map. put ("c", "Level c"); Iterator <Entry <String, String> it = map. entrySet (). iterator (); while (it. hasNext () {Entry <String, String> e = it. next (); response. getWriter (). println ("Key:" + e. getKey () + "; Value:" + e. getValue () ;}} returned result: [html] ------ unordered (random output) ------ Key: 3; Value: Level 3 Key: 2; Value: Level 2 Key: 1; Value: Level 1 Key: B; Value: Level B Key: c; Value: Level c Key: a; Value: Level a ------ ordered (but by default, cannot be specified) ------ Key: 1; Value: Level 1 Key: 2; Value: Level 2 Key: 3; Value: Level 3 Key: a; Value: Level a Key: B; value: Level B Key: c; Value: Level c ------ ordered (output according to the input order) ------ Key: 1; Value: Level 1 Key: 2; Value: Level 2 Key: 3; Value: Level 3 Key: a; Value: Level a Key: B; Value: Level B Key: c; Value: Level c 4. summary: php arrays are implemented using hashmap. Therefore, it is easy to understand hashmap after learning php. linkedhashmap is similar to php arrays.