package com.yjf.esupplier.common.test; import java.util.LinkedHashMap; import java.util.Set; /** * @author shusheng * @description * @Email shusheng@yiji.com * @date 2018/12/18 13:40 */ public class LinkedHashMapDemo { /** * LinkedHashMap:是Map接口的哈希表和鏈表實現,具備可預知的迭代順序由哈希表保證鍵的惟一性 * 由鏈表保證鍵盤的有序(存儲和取出的順序一致) */ public static void main(String[] args) { LinkedHashMap<String, String> hm = new LinkedHashMap<String, String>(); //建立並添加元素hm.put("100", "hello"); hm.put("101", "world"); hm.put("102", "java"); hm.put("103", "javaee"); hm.put("104", "android"); //遍歷 Set<String> set = hm.keySet(); for (String key : set) { String value = hm.get(key); System.out.println(key + "---" + value); } } }