Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

public class Main {
    public static void main(String[] argv) throws Exception {
        Map<String, Integer> map = new HashMap<String, Integer>();
        map = new TreeMap();

        map.put("a", new Integer(1));
        map.put("b", new Integer(2));
        map.put("c", new Integer(3));

        int size = map.size(); // 2

        Object oldValue = map.put("a", new Integer(9)); // 1

        oldValue = map.remove("c"); // 3

        Iterator it = map.keySet().iterator();
        while (it.hasNext()) {
            Object key = it.next();
        }

        it = map.values().iterator();
        while (it.hasNext()) {
            Object value = it.next();
        }
    }
}