HashMap의 keySet 메소드를 통해 값을 가져오는 방법

2013. 1. 2. 16:33Development/[Java] 자바

728x90

HashMap의 keySet 메소드를 통해 map안의 값을 가져오는 방법(Iterator사용)

public static void main(String[] args) {

    Map<String, String> testMap = new HashMap<String, String>();
    map.put("no", "1");
    map.put("id", "hello");
    map.put("pass", "1234");
    
    Iterator<String> iter = map.keySet().iterator();
    while (iter.hasNext()) {
        String keys = (String) iter.next();
        System.out.print("키값="+keys);
        System.out.println(" 밸류값="+map.get(keys));
    }
}    

[ 출력 결과 ]
key=no value=1, key=id value=hello, key=pass value=1234     

728x90