티스토리 뷰

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.tistory.jononeworld;
 
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
 
public class MapIterationSample {
    
    public static void main(String[] args) {
        Map<String, Object> map = new HashMap<String, Object>();
 
        map.put("키1""값1");
        map.put("키2""값2");
        map.put("키3""값3");
        map.put("키4""값4");
        map.put("키5""값5");
        map.put("키6""값6");
 
        //방법1
        Iterator<String> keys = map.keySet().iterator();
        while( keys.hasNext() ){
            String key = keys.next();
            System.out.printlnString.format("키: %s, 값: %s", key, map.get(key)) );
        }
 
        //방법2
        for( Map.Entry<String, Object> elem : map.entrySet() ){
            System.out.printlnString.format("키: %s, 값: %s", elem.getKey(), elem.getValue()) );
        }
 
        //방법3
        forString key: mep.keySet() ){
            System.out.printlnString.format("키: %s, 값: %s", key, map.get(key)) );

 

[출처] http://stove99.tistory.com

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함