- public class MapTest {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
- Map<String, Integer> mp = new TreeMap<String, Integer>();
- mp.put("张三",25);
- mp.put("李四", 38);
- mp.put("王五", 46);
- mp.put("赵六", 78);
-
- Set<Map.Entry<String, Integer>> s = mp.entrySet();
- for(Iterator<Entry<String, Integer>> it = s.iterator(); it.hasNext();){
- Map.Entry<String, Integer> me = it.next();
- //操作元素
- if(me.getKey().equals("张三"))
- it.remove();
- if(me.getValue().equals("78"))
- it.remove();
-
- }
- System.out.println(mp);
-
- }
- }
复制代码 |