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

		}

使用ArrayList代理进行Map的排序

Categories: Java; Tagged with: ; @ January 28th, 2009 18:18

某Map中散乱的存放着如下信息:

abce.com (1), cde.com (1), abc.com (3), def.com (1), abd.com (2), sfaf.com (1), bcd.com (2)

为了进行排寻 使用ArrayList的sort进行排序.

通过new ArrayList(collection) 将Map中的Value引用到新建立的ArrayList中,

		//--以下为排序
		ArrayList alDomains = new ArrayList();
		alDomains = new ArrayList(domains.values());
		System.out.println(alDomains);
		Collections.sort(alDomains, null);
		System.out.println(alDomains);

打印:

[abce.com (1), cde.com (1), abc.com (3), def.com (1), abd.com (2), sfaf.com (1), bcd.com (2)] – 排序前

[abc.com (3), abce.com (1), abd.com (2), bcd.com (2), cde.com (1), def.com (1), sfaf.com (1)] – 排序后



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