SNOWFLAKES DRAWING PAPER

[JAVA] HashMap 변수에서 키값만 빼오기 본문

개발/JAVA

[JAVA] HashMap 변수에서 키값만 빼오기

눈송2 2009. 10. 23. 09:28

   
public static void main(String[] args) {
    HashMap h = new HashMap();
    h.put("test", "testval");
    h.put("test2", "testval2");
   
    Set set  = h.keySet();
   
    Iterator it = set.iterator();
    while(it.hasNext())
        System.out.println( it.next() );
       
    }
   
}



// 출력
test
test2













import java.util.HashMap;
import java.util.Iterator;

public class HashMapSample
{
    public static void main(String[] args)
    {
        HashMap<Integer, String> hm = new HashMap<Integer, String>();

        hm.put(1, "일");
        hm.put(2, "이");
        hm.put(3, "삼");
        hm.put(4, "사");
        hm.put(5, "오");
   
        Iterator<Integer> iter = hm.keySet().iterator();
   
        while(iter.hasNext())
        {
            int nCount    = iter.next();
            System.out.println(hm.get(nCount));
        }
    }
}

결과는 당근






Comments