반응형
=================================
=================================
=================================
출처:
http://blog.naver.com/popori1100?Redirect=Log&logNo=130074419880
import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; public class HashMapExample { public static void main(String[] args) { HashMap<Object,String> hm=new HashMap<Object,String>(); // adding or set elements in HashMap by put method key and value pair hm.put(new Integer(2), "Two"); hm.put(new Integer(1), "One"); hm.put(new Integer(3), "Three"); hm.put(new Integer(4), "Four"); // Get hashmap in Set interface to get key and value Set s=hm.entrySet(); // Move next key and value of HashMap by iterator Iterator it=s.iterator(); while(it.hasNext()) { // key=value separator this by Map.Entry to get key and value Map.Entry m =(Map.Entry)it.next(); // getKey is used to get key of HashMap int key=(Integer)m.getKey(); // getValue is used to get value of key in HashMap String value=(String)m.getValue(); System.out.println("Key :"+key); System.out.println("value :"+value); } } }
Output
Key :1
value :One
Key :2
value :Two
Key :3
value :Three
Key :4
value :Four
[출처] Java – HashMap Example|작성자 popori1100
=================================
=================================
=================================
반응형
'JAVA' 카테고리의 다른 글
[java] URLConnection을 이용한 파일 전송 (0) | 2011.03.23 |
---|---|
[java] Java - String 을 InputStream 으로 만들기 (0) | 2011.03.22 |
[IDE] 이클립스 단축키 모음 (0) | 2011.01.20 |
[java] 자바 외부 프로그램 실행하기(실행경로에 맞추어 정확히) (0) | 2011.01.19 |
[java] 자바 RTF파일을 받아 출력시 데이터를 고쳐주어야 할 것 (0) | 2010.12.07 |