java遍历Map时remove删除元素

来源:互联网 发布:人工智能会超越人脑吗 编辑:程序博客网 时间:2024/04/25 08:48
http://blog.csdn.net/itmyhome1990/article/details/12655411

public class T {

public static void main(String[] args) {
// TODO Auto-generated method stub
List> list = newArrayList>();
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
}

}
0 0
原创粉丝点击