发布网友 发布时间:2022-04-22 05:57
共1个回答
热心网友 时间:2023-09-29 21:15
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
public class TestHm {
public static void main(String atgs[]){
HashMap hm=new HashMap();
//添加内容
hm.put("Object key1", "Object value");
hm.put("Object key2", "Object value");
hm.put("Object key3", "Object value");
hm.put("Object key4", "Object value");
//删除Object key3
hm.remove("Object key3");
//创建数组,声明i作为数组下标
String s[]=new String[hm.size()];
int i=0;
//显示内容
Set set=hm.keySet();
Iterator it=set.iterator();
while(it.hasNext()){
String t=(String)it.next();
System.out.println(t);
s[i++]=t;
}
//测试数组是否添加值
System.out.println("===================");
for(int t=0;t<=2;t++)
System.out.println(s[t]);
}
}