package demo1; import com.sun.source.tree.LineMap; import java.util.HashMap; import java.util.LinkedHashMap; /* * java.util.LinkedHashMap<K,V> entends HashMap<K,V> Map 接口的哈希表和链接列表实现,具有可预知的迭代顺序 底层原理: 哈希表+链表(记录元素的顺序) */ public class DemoLinkedHashMap { public static void main(String[] args) { HashMap<String,String> map = new HashMap<>(); map.put("a","a"); map.put("b","b"); map.put("c","c"); map.put("a","d"); // System.out.println(map);//key不允许重复,无序 LinkedHashMap<String,String> link = new LinkedHashMap<>(); link.put("a","a"); link.put("b","b"); link.put("c","c"); link.put("a","d"); System.out.println(link); } }
Java 基础 LinkedHashMap
最新推荐文章于 2023-08-31 14:37:40 发布