package hashmap;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
/**
* TODO 对HashMap的迭代
* @author fxfeng
* @create 2005-12-20
*/
public class HashMapTest {
private static Map temp = new HashMap();
public static void main(String[] args) {
// TODO Auto-generated method stub
for(int i=0; i<10; i++){
String str = "string" + i;
temp.put(new Integer(i), str);
}
if(temp.containsKey(new Integer(5))){
System.out.println("Contains!");
}else{
System.out.println("No contains!");
}
System.out.println("/");
for(Iterator it = temp.entrySet().iterator(); it.hasNext(); ){
Map.Entry e = (Map.Entry)it.next();
System.out.println("key: " + e.getKey());
System.out.println("value: " + e.getValue());
}
System.out.println("//");
}
}
循环MAP
最新推荐文章于 2023-11-26 11:02:03 发布