java 集合自我总结

                         ##**java 集合的自我总结**

/*
Collection:
{ vector 实现了Stack;
List 有序 值不唯一(有放入顺序))
ArrayList 底层是一个数组
LinkedList 底层为链表 LinkedList实现了Queue接口

	 Set 无序 值唯一
	 hashSet  无序    是根据hashCode的值选择位置    底层是hashMap hashMap是用哈希表(链表+数组)算法实现的
	 TreeSet  有序 (自然排序)自定义排序需要实现Comparable       底层是Treemap(通过Key来存储Set的值) TreMap是用红黑二叉树实现的}
	 Map:
	 hashMap 无序  <K,V>  k(set)  V(collecyion)
	 TreeMap 有序   (红黑二叉树实现)
	 Map 和Set的关系:
	 都采用了哈希表的实现方法,Set是用Map实现的 只用Map的Key存储元素,Map等同于Set
	 
	 * 

//向Map中存数据

if(map.containsKey(a)){
map.put(a,map.get(a)+1);
}
else{
map.put(a,1);
}
*

输出示例
for(String m:map.keySet())
{

System.out.println(m+map.getKey());
}
*
*/


map
//按照Value的升序排列
将Map转换为List才可按照value排列
Entry为map内部类
//原来默认是按照key的顺序排列

List<Entry<Integer, Integer>> entry = new ArrayList<Entry<Integer, Integer>>(map.entrySet());

Collections.sort(entry, new Comparator<Entry<Integer, Integer>>() {

	//升序
	public int compare(Entry<Integer, Integer> o1, Entry<Integer, Integer> o2) 
	{
		return o1.getValue().compareTo(o2.getValue());
	}
});
for(Entry<Integer, Integer> entrys:entry) {
	System.out.println(entrys.getKey()+"出现的次数是:"+entrys.getValue());
	
	}

请大神多多指正!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值