HashMap遍历
package hmy.test;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public static void main(String[] args) {
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < 1; i++) {
map.put("" + i, "qwee");
}
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
System.out.println("1:" + key + val);
if(entry.getValue().equals("qwee")){
System.out.println("12344");
iter.remove();
}
}
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println(entry.getKey() + "--->" + entry.getValue());
if(entry.getValue().contains("qwee")){
System.out.println("12344");
iter.remove();
}
}
Iterator iter1 = map.keySet().iterator();
while (iter1.hasNext()) {
Object key = iter1.next();
Object val = map.get(key);
System.out.println("2:" + key + val);
}
for (String key : map.keySet()) {
System.out.println("key= " + key + " and value= " + map.get(key));
}
}
}