Map 컬렉션 클래스
Map 특징
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Map03 { public static void main(String[] args) { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> ele = new HashMap<String, Object>(); ele.put("no", 1); ele.put("title", "제목입니다"); ele.put("date", "2022-11-14"); ele.put("count", 5); ele.put("write", "opp"); list.add(ele); ele = new HashMap<String, Object>(); ele.put("no", 2); ele.put("title", "2번입니다"); ele.put("date", "2022-11-14"); ele.put("count", 15); ele.put("write", "테스터"); list.add(ele); ele = new HashMap<String, Object>(); ele.put("no", 3); ele.put("title", "3번입니다"); ele.put("date", "2022-11-15"); ele.put("count", 150); ele.put("write", "누구냐"); list.add(ele); ele = new HashMap<String, Object>(); ele.put("no", 4); ele.put("title", "4번입니다~~~~"); ele.put("date", "2022-11-15"); ele.put("count", 159); ele.put("write", "뉴비"); list.add(ele); ele = new HashMap<String, Object>(); ele.put("no", 5); ele.put("title", "오 번입니다~~~~"); ele.put("date", "2022-11-16"); ele.put("count", 25); ele.put("write", "행인1"); list.add(ele); System.out.println(list); // 출력값 //[ //{date=2022-11-14, no=1, count=5, title=제목입니다, write=opp}, //{date=2022-11-14, no=2, count=15, title=2번입니다, write=테스터}, //{date=2022-11-15, no=3, count=150, title=3번입니다, write=누구냐}, //{date=2022-11-15, no=4, count=159, title=4번입니다~~~~, write=뉴비}, //{date=2022-11-16, no=5, count=25, title=오 번입니다~~~~, write=행인1} //] // 출력문 System.out.println("------------------------------------------------------------------"); System.out.println("번호\t제목\t날짜\t조회수\t글쓴이"); for (int i=0; i<list.size(); i++) { //System.out.println(list.get(i)); ele = list.get(i); //System.out.println(ele); System.out.print(ele.get("no")+"\t"); System.out.print(ele.get("title")+"\t"); System.out.print(ele.get("date")+"\t"); System.out.print(ele.get("count")+"\t"); System.out.print(ele.get("write")+"\n"); } } }