총 두 가지 방법이 있습니다.
HashMap 뿐만 아니라 Collection 객체들은 다 변경이 가능할 것 같더군요!
package h2m; import java.util.ArrayList; import java.util.HashMap; /** * @Project : Blog * @Name : HashMapToArrayList.java * @Date : 2008. 8. 8. * @Author : Keep Burning * @Blog : http://keepburning.tistory.com * @Description : Converting HashMap To ArrayList */ public class HashMapToArrayList { static public ArrayList getArrayListFromHashMap1(HashMap hashMap) { return new ArrayList( hashMap.values() ); } static public ArrayList getArrayListFromHashMap2(HashMap hashMap) { ArrayList arrayList = new ArrayList(); arrayList.addAll( hashMap.values() ); return arrayList; } public static void main(String[] args) { HashMap hashMap = new HashMap(); ArrayList arrayList1; ArrayList arrayList2; hashMap.put("key1", "value1"); hashMap.put("key2", "value2"); hashMap.put("key3", "value3"); arrayList1 = getArrayListFromHashMap1(hashMap); arrayList2 = getArrayListFromHashMap2(hashMap); for(int i=0 ; i<arrayList1.size() ; i++) { System.out.println("arrayList1[" + i + "] : " + arrayList1.get(i)); } for(int i=0 ; i<arrayList2.size() ; i++) { System.out.println("arrayList2[" + i + "] : " + arrayList2.get(i)); } } }
'I/T > Java' 카테고리의 다른 글
ExecutionTime (실행 시간 측정) (2) | 2009.11.24 |
---|---|
Eclipse 설치 (eclipse-jee-europa-winter-win32) (0) | 2009.06.02 |
JDK 설치 (JDK 6 Update12) (0) | 2009.06.02 |
[I/T>Java] Converting StringArray To List (0) | 2009.04.27 |
[I/T>Java] Generating Random String (0) | 2009.04.27 |