본문 바로가기
Work/java

java HashMap 에서 값 순서대로 꺼내기

by 승수 2014. 2. 24.


HashMap에서 순서대로 key 값이나 value 값 가져오기


import java.util.HashMap;

import java.util.Iterator;

import java.util.Collection;


HashMap hasm = new HashMap();


hasm.put("key1","value1");

hasm.put("key2","value2");

hasm.put("key3","value3");


Collection k = hasm .keySet();

Iterator itr = k.iterator();

while(itr.hasNext()){

System.out.println("=======key========"+itr.next());

}


Collection v = hasm .values();

Iterator itrv = v.iterator();

while(itrv.hasNext()){

System.out.println("=======value========"+itrv.next());

}