Map hmap = new HashMap() 实例的示例;
Map tmap = 新树图();
Map hmap = new HashMap();2.public void putAll(Map map)
hmap.put(1, e1”);
hmap.put(2, e2”);
hmap.put(3, e3”);
Map hmap2 = new HashMap();
hmap2.put(4, e4”);
hmap2.put(5, e5”);
hmap.putAll(hmap2);
String e2 = (String) hmap.get(2);4.public Object remove(object key):
hmap.remove(1);5. public boolean containsKey(对象键)
for(对象键:hmap.keySet()) {8. public Set entrySet():
对象值 = hmap.get(key);
System.out.println(值);
}
for (Map.Entry entry: hmap.entrySet()
{
System.out.println(entry.getKey() + -” + entry.getValue());
}
此映射仅接受对象 Integer 用于键和 String表示值。通用性的优点是无需强制转换即可访问元素:Map<整数、字符串>hmap = 新 HashMap<整数、字符串>();
import java.util.Hashtable;结果:
import java.util.Map;
public class 示例 {
public static void main(String a[]){
//creation
Mapht = new Hashtable ();
//添加键值
ht.put(1, java”);
ht.put(2, C”);
ht.put(3, C++”);
for (Map.Entryentry: ht.entrySet())
{
int key = entry.getKey();
字符串值 = entry.getValue();
System.out.println(键 + -” + 值);
}
}
}
3-C++参考:
2-C
1-java
Please disable your ad blocker and refresh the window to use this website.