Map hmap = new HashMap();
Map tmap = new TreeMap();
Map hmap = new HashMap();2.public void putAll(マップ)
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(Object key)
for(Object key : hmap.keySet()) {8. public Set entrySet():
Object value = hmap.get(key);
System.out.println(値);
}
for (Map.Entry entry: hmap.entrySet()
{
System.out.println(entry.getKey() + "-" + entry.getValue());
}
このマップはオブジェクトのみを受け入れます Integer (キー用) と String (値用)。ジェネリック性の利点は、キャストせずに要素にアクセスできることです:Map<整数、文字列>hmap = new 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.