Java: Map遍历

Categories: Java; Tagged with: ; @ January 26th, 2010 10:43
		// 2. 遍历map中所有的元素
		Iterator>> iter = mapSheet.entrySet().iterator();
		while(iter.hasNext()) {
			Entry> entry = iter.next();
			int sheetIndex = entry.getKey(); // Key
			List listReportItems = entry.getValue(); // Value

		}

在ActionScript 中使用HashMap – Use HashMap in ActionScript

Categories: Flex; Tagged with: ; @ January 10th, 2009 10:58

HashMap:

HashMap的key必须为String类型, 如果要使用任意类型的key, 应选择使用Dictionay而非HashMap

主要操作如下:

	private function init():void {
		//新建对象
		var obj:Object = new Object();

		//增加key-value
		obj["name"] = "liguoliang";  //格式: Object[key] = value
		obj["age"] = 25; 			 //注意: key必须为String, value可以为任意类型

		//使用for..in...遍历所有的key - value
		for(var k:String in obj) {
			trace("Key: " + k + " - value: " + obj[k]);
		}

		//使用for each..in遍历HashMap
		for each( var v:* in obj) {
			trace("value: " + v);
		}
		
		//删除一个key-value
		delete obj["age"];
		
		//使用for..in...遍历所有的key - value
		for(var k:String in obj) {
			trace("Key: " + k + " - value: " + obj[k]);
		}
	}

输出结果如下:

Key: name – value: liguoliang

Key: age – value: 25

value: liguoliang

value: 25

Key: name – value: liguoliang



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.