Java/중요클래스

HashMap 특성

Bohemian life 2012. 4. 11. 22:54
package com.map;//HashMap특성

import java.util.HashMap;

public class HashMapExample1 {
	public static void main(String[] args) {
		//HashMap : 정렬을 보장하지 않는다 , Key와 Value의 null 값 인정함
		//key와 value를 쌍으로 저장한다 , key의 중복이 허용되지 않는다
		HashMap<string, integer=""> map = new HashMap<string, integer="">();
		map.put("해리", new Integer(95));
		map.put("헤르미온느",new Integer(100));
		map.put("론", new Integer(85));
		map.put("드레이코",new Integer(93));
		map.put("네빌",new Integer(70));
		map.put(null, new Integer(40));
		map.put("신봉선", null);
		//중복이 허용이 되지 않아 덮어씌워짐(key값)
		map.put("헤르미온느", new Integer(0));
		
		
		
		System.out.println(map);
		
		Integer num = map.get("헤르미온느");
		System.out.println("헤르미온느의 성적은? : "+num);
		
	}

}
{null=40, 헤르미온느=0, 신봉선=null, 네빌=70, 해리=95, 드레이코=93, 론=85}

헤르미온느의 성적은? : 0