java遍历Map时remove删除元素 分类: Android开发 2014-05-30 10:58 84人阅读 评论(0) 收藏

http://blog.csdn.net/itmyhome1990/article/details/12655411

public class T {

public static void main(String[] args) {
// TODO Auto-generated method stub
List> list = new ArrayList>();
Map m1 = new HashMap();
m1.put("NAME", "北京");
m1.put("STATE", "1");
Map m2 = new HashMap();
m2.put("NAME", "上海");
m2.put("STATE", "1");
Map m3 = new HashMap();
m3.put("NAME", "广州");
m3.put("STATE", "2");
list.add(m1);
list.add(m2);
list.add(m3);
Iterator> ite = list.iterator();
while(ite.hasNext()){
Map m = ite.next();
//如果STATE值为2的删除
if("2".equals(m.get("STATE"))){
ite.remove();
}
}
for(Map map:list){
System.out.println(map.get("NAME")+"--"+map.get("STATE"));
}
System.out.println("--------------------");
Integer k = 10;
String m = "10";
System.out.println("10".equals(k));   //false
System.out.println("10".equals(m));   //true
}

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2014-05-30 10:58  leansmall  阅读(228)  评论(0编辑  收藏  举报