Java HashMap

public class Demo_HashMap {
	public static void main(String[] args) {
		Map<Object, Object> hashMap = new HashMap<Object, Object>();
		hashMap.put("1", 2);
		hashMap.put(3, 4);

		Iterator<Entry<Object, Object>> iterator = hashMap.entrySet().iterator();
		while (iterator.hasNext()) {
			Entry<Object, Object> entry = iterator.next();
			Object key = entry.getKey();
			Object value = entry.getValue();
			// System.out.println(key + "------------>" + value);
		}

		Map<Object, Object> hashMap2 = new HashMap<Object, Object>();
		hashMap2.put("德羅巴", "科特迪瓦");
		hashMap2.put("大羅", "巴西");
		hashMap2.put("斯塔姆", "荷蘭");
		// get方法 ,根據key 獲取value
		System.out.println(hashMap2.get("德羅巴"));

	}

 

相關文章
相關標籤/搜索