Map

引用参考:
--Map的5种遍历方法
http://blog.csdn.net/zhu1qiu/article/details/71170850
--谈谈java中遍历Map的几种方法
https://www.cnblogs.com/zhaoguhong/p/7074597.html?utm_source=itdadao&utm_medium=referral
--HashMap简单实现原理及遍历map的几种方式
http://blog.csdn.net/jiangzhongwei_/article/details/51992621

	//遍历map
	public static void main(String[] args) {
		Map<String,String[]> currentMap = new HashMap<String,String[]>();
		String currentString = "";
//      currentMap = ...;//给currentMap赋值
        Iterator<String> paramIt = currentMap.keySet().iterator();//遍历Map
        int icount = 0;
        while(paramIt.hasNext()){
        	icount ++;
        	String key = paramIt.next();
        	String[] valueArray = currentMap.get(key);
        	String value="";
        	if(valueArray.length>0){
//        		value=...;//给value赋值
        	}
        	if(icount == currentMap.size()){
        		currentString += key + "=" + value;
        	}else{
        		//
        	}
        }
	}


解析map的key和value
public class Demo {
	public static void main(String[] args) {
		Map<String, String> startMap=new HashMap<String, String>();
		startMap.put("class1", "一年级有30名学生");
		startMap.put("class2", "二年级有31名学生");
		startMap.put("class3", "三年级有28名学生");
		startMap.put("class4", "四年级有29名学生");
		Collection<String> coll=startMap.values();
		System.out.println("coll长度="+coll.size());
		for (String value : coll) {
			System.out.println("值value="+value);
		}
		Set<String> set=startMap.keySet();
		System.out.println("set长度="+set.size());
		for (String key : set) {
			System.out.println("键key="+key);
		}
	}
}

效果图:


【concurrenthashmap】
--ConcurrentHashMap总结
http://www.importnew.com/22007.html
--HashMap和ConcurrentHashMap浅析
https://blog.csdn.net/zldeng19840111/article/details/6703104
--为什么要使用ConcurrentHashMap而不是HashMap
https://blog.csdn.net/l_h_y123/article/details/53330763
--Java中的几个HashMap/ConcurrentHashMap实现分析
http://www.importnew.com/19685.html



猜你喜欢

转载自franciswmf.iteye.com/blog/2412182
Map
今日推荐