package org.westos.LinkedHashMap集合博客练习;
import java.util.LinkedHashMap;
import java.util.Set;
/**
*LinkedHashMap<K,V> :是Map接口基于哈希表和链接列表实现的
*
*哈希表保证键的唯一性
*链接列表保证元素有序性(存储和取出一致)
*/
public class Text1 {
public static void main(String[] args) {
LinkedHashMap<String,String> map = new LinkedHashMap<String,String>();
//添加元素
map.put("it001", "hello");
map.put("it002", "mysql");
map.put("it003", "world");
map.put("it004", "javaweb");
map.put("it001", "javaee");
//遍历
Set<String> set = map.keySet();
for(String s:set) {
String str = map.get(s);
System.out.println(s+"---"+str);
}
// it001---javaee 将按照键的输入顺序进行输出
// it002---mysql
// it003---world
// it004---javaweb
}
}
5.13LinkedHashMap集合
最新推荐文章于 2024-05-26 15:43:17 发布