// 풀어보기 1,2
public class JumsuArray {
public static void main(String[] args) {
//List<String> list2 = new ArrayList<String>();
List<Map> list1 = new ArrayList<Map>();
Map<String,String> map1 = new HashMap<String,String>();
map1.put("id","test1");
map1.put("eng","90");
map1.put("kor","80");
map1.put("math","84");
list1.add(map1);
map1 = new HashMap<String,String>();
map1.put("id","test2");
map1.put("eng","80");
map1.put("kor","82");
map1.put("math","90");
list1.add(map1);
System.out.println( list1 );
System.out.println( list1.get(1) ); // Map 데이터
System.out.println( list1.size() ); // 2
System.out.println( list1.get(0).size() ); // 4
System.out.println();
for( int i=0; i<list1.size(); i++ ) { // 2번 회전
Map<String,String> map = new HashMap<String,String>();
map = list1.get(i); // 각 맵을 추출
Iterator<String> keys = map.keySet().iterator();
while( keys.hasNext() ) {
String key = keys.next(); // id,eng,kor,math
String value = map.get(key);
System.out.println( key+":"+value );
}
//System.out.println( map );
}
}
}
// 풀어보기 3,4,5,6
public class BoardListMap {
public static void main(String[] args) {
List<Map> list1 = new ArrayList<Map>();
Map<String,String> map1 = new HashMap<String,String>();
map1.put("no","1");
map1.put("hit","35");
map1.put("rdate","2021-05-01");
map1.put("name","홍길동");
map1.put("title","공지사항1");
list1.add(map1);
map1 = new HashMap<String,String>();
map1.put("no","2");
map1.put("hit","3");
map1.put("rdate","2021-05-05");
map1.put("name","제임스");
map1.put("title","공지사항2");
list1.add(map1);
System.out.println( list1 );
int hap = 0;
for( int i=0;i<list1.size();i++ ) {
String rdate = (String)list1.get(i).get("rdate");
String hit = (String)list1.get(i).get("hit");
rdate = rdate.replace("-","");
list1.get(i).put("rdate", rdate);
int hit2 = Integer.parseInt(hit) + 100;
list1.get(i).put("hit", hit2);
hap += hit2;
}
System.out.println( list1 );
System.out.println( "총 조회수 : " + hap + "건" );
System.out.println( "조회수평균 : " + hap/list1.size() + "건" );
}
}