日期:2014-05-20 浏览次数:20812 次
import java.util.*; import java.util.Map.Entry; public class test { public static void main(String[] args) { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); //在这里也可以用list.get(i)来取得第i个元素 Iterator it = list.iterator(); while (it.hasNext()) { Map<String, Object> map = (Map) it.next(); Set<Entry<String, Object>> entrySet = map.entrySet(); for (Entry<String, Object> entry : entrySet) { //do something................... } } } }
------解决方案--------------------
package com.alaric.test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
*
* @Description :
* @author alaric
* @version 1.0
* @created 2012 May 12, 2012 8:31:23 PM
* @fileName com.alaric.test.Test.java
*/
public class Test {
public static void main(String[] args) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
/**
* list 可以用for each 来遍历 也可用迭代器来遍历
*/
for(Map<String, Object> map:list){
Iterator<String> iterator = map.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
Object obj = map.get(key);
}
}
/**
* map 可以用for each 来遍历 也可用迭代器来遍历
*/
Iterator <Map<String,Object>>it = list.iterator();
while (it.hasNext()) {
Map<String, Object> map = (Map<String,Object>) it.next();
Set<Entry<String, Object>> entrySet = map.entrySet();
for (Entry<String, Object> entry : entrySet) {
//do something...................
}
}
}
}
建议你好好掌握下j2se基础,比如集合,异常,io,多线程这些基础,基础掌握了,这个问题有很多种做法,而且每种做法的性能也不一样。
http://www.happyalaric.com alaric 个人技术博客站欢迎你浏览。