Map hmap = new HashMap();
지도 tmap = new TreeMap();
Map hmap = new HashMap();2. public void putAll(지도 지도)
hmap.put(1, "e1");
hmap.put(2, "e2");
hmap.put(3, "e3");
지도 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 항목: 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.Entry항목: 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.