Java HashMap Örneği

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
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

/**
 *
 * @author ugur
 */

public class Main {

    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) {

        HashMap<Integer, String> map = new HashMap<Integer, String>();

        map.put(1, "one");
        map.put(2, "two");
        map.put(3, "three");

        Set<Integer> ks = map.keySet();

        Iterator<Integer> i = ks.iterator();

        while (i.hasNext()) {
            int key = i.next();
            System.out.print(key + " ");
            System.out.println(map.get(key));
        }
    }
}

Output:
run:
1 one
2 two
3 three
BUILD SUCCESSFUL (total time: 0 seconds)

Leave a Reply