package com.test.Test11;import java.util.*;public class Test01LinkedHashMap {public static void main(String[] args) {/** 增加:put(K key,V value)* 删除:clear() remove(Object key)* 修改:* 查看:entrySet() get(Object key) keySet() size() values()* 判断:containsKey(Object key) containsValue(Object value)* equals(Object o) isEmpty()* *///LinkedHashMap实现类 特点:唯一,有序(按照输入顺序进行输出)。Map<String,Integer> map = new LinkedHashMap<>();map.put(null,1010); //key是null值不报错map.put(null,2020); //存入多个null不报错System.out.println(map.put("lili",10101010)); //nullmap.put("nana",2143535);map.put("feifei",3456789);System.out.println(map.put("lili",346565767));//10101010map.put("mingming",12323);System.out.println(map.size()); //4(上面的添加了5对数据,只出来4对数据)System.out.println(map);//下面的就是有序的了,先插入的null 然后依次插入的是lili,nana,feifei,mingming//{null=2020, lili=346565767, nana=2143535, feifei=3456789, mingming=12323}/*map.clear(); //清空System.out.println(map.size()); //0System.out.println(map); //{}*//*map.remove("feifei");System.out.println(map.size()); //3System.out.println(map); //{nana=2143535, lili=346565767, mingming=12323}*/System.out.println(map.containsKey("lili")); //trueSystem.out.println(map.containsValue(12323));//trueHashMap<String,Integer> map2 = new HashMap<>();System.out.println(map2.put("lili",10101010)); //nullmap2.put("nana",2143535);map2.put("feifei",3456789);System.out.println(map2.put("lili",346565767));//10101010map2.put("mingming",12323);// map2.put("mingming2",12323); //修改了一下这个元素下面的equals输出就不一样了System.out.println(map2.size()); //4(上面的添加了5对数据,只出来4对数据)System.out.println(map2);//{nana=2143535, lili=346565767, mingming=12323, feifei=3456789}System.out.println(map == map2); //falseSystem.out.println(map.equals(map2)); //true equals进行了重写,比较的是集合中的值是否一致。//map.clear();//清空map 清空后下面的map.isEmpty()就变成了true了System.out.println("判断是否为空:"+map.isEmpty()); //判断是否为空:falseSystem.out.println("查看值是多少:"+map.get("nana"));//查看值是多少:2143535System.out.println("------------------");//keySet()对集合中的key进行遍历查看Set<String> strings = map.keySet();for(String s:strings){System.out.println(s); //得到了所有的key值}/** nanalilimingmingfeifei** */System.out.println("------------------");//values() 对集合中的value进行遍历查看Collection<Integer> values = map.values();for (Integer i:values) {System.out.println(i);//得到了所有的value值}/** 2143535346565767123233456789** */System.out.println("------------------");//get(Object key) keySet()Set<String> set2 = map.keySet();for(String s:set2){System.out.println(map.get(s)); //get的方式遍历所有的元素}/** 2143535346565767123233456789*** */System.out.println("------------------");//entrySet() 得到的是一对key value数据Set<Map.Entry<String, Integer>> entries = map.entrySet();for(Map.Entry<String, Integer> e:entries) {System.out.println(e.getKey()+"------"+e.getValue());}/*nana------2143535lili------346565767mingming------12323feifei------3456789*/} }