Java

ArrayList 안의 HashMap

유호야 2020. 12. 1. 12:08
반응형
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		
		System.out.println(list);
		
		HashMap<String, String> personMap1 = new HashMap<String, String>();
		
		personMap1.put("Pau", "Poland");
		personMap1.put("Yujin", "South Korea");
		personMap1.put("Cristian", "Ecuador");
		personMap1.put("Erin", "USA");
		
		System.out.println(personMap1);
		
		HashMap<String, String> personMap2 = new HashMap<String, String>();
		
		personMap2.put("Pau", "25");
		personMap2.put("Yujin", "24");
		personMap2.put("Cristian", "26");
		personMap2.put("Erin", "28");
		
		System.out.println(personMap2);
		
		list.add(personMap1);
		list.add(personMap2);
		
		System.out.println(list);
		
		HashMap<String, String> takeMap1 = (HashMap<String, String>)list.get(0);
		String name1 = takeMap1.get("Pau");
		String age1 = takeMap1.get("Yujin");
		
		System.out.println(name1);
		System.out.println(age1);
		
		HashMap<String, String> takeMap2 = (HashMap<String, String>)list.get(1);
		String name2 = takeMap2.get("Pau");
		String age2 = takeMap2.get("Yujin");
		
		System.out.println(name2);
		System.out.println(age2);
반응형

'Java' 카테고리의 다른 글

pageContext  (0) 2020.12.02
EL(Expression language)란?  (0) 2020.12.02
JSTL <c:forEach> 사용법  (0) 2020.12.01
DAO vs DTO(=VO) 개념 알아보기  (0) 2020.12.01
ArrayList 란?  (0) 2020.11.30