Collection结构图,及HashMap和Hashtable的区别

1.Collection的结构图:Collection结构图,及HashMap和Hashtable的区别
2.
HashMap和Hashtable的区别:
hashMap和Hash是Map接口下的俩个实现类,因为Map对象是键值对存在的,因为Map对象是键值对存在的,所以此两类也是键值对存在的。
HashMap是线程非安全的,hashtable是线程安全的,所以hashMap的效率高于hashtable。
HashMap允许null键null值,键最多只可以有一个null,值不受限制。而hashtable值和键不允许为null.
TreeMap:是基于红黑树的Map集合 特点:排序,唯一
注意:Hashtable中的“t”是小写

Map的遍历方式:.通过Key得到值的遍历方式
Map<String,String> map=new HashMap<String, String>();
//添加元素
map.put("1","马利伊");
map.put("2","文章");
map.put("3","黄晓明");
map.put("4","Baby");
map.put("5","孙悟空");
map.put("6","齐天大圣");
Set<String> strings = map.keySet();
for (String string: strings) {
String s = map.get(string);
System.out.println(s);
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
演示Collections和collection的区别:
//Collections完全由在 collection 上进行操作或返回 collection 的静态方法组成,里面有方法,sort排序,min返回集合的最小元素,max返回集合的最大元素

ArrayList<Integer> list=new ArrayList<Integer>();
list.add(4);
list.add(2);
list.add(1);
list.add(7);
list.add(45);

System.out.println("排序前"+list);
Collections.sort(list);
System.out.println("排序后"+list);
System.out.println("最小值"+Collections.min(list));
System.out.println("最大值"+Collections.max(list));