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

1.Collection的结构图: aaa
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));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值