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.Set;

public class Main {
    public static void main(String[] args) {
        String text = "A,B,C,D";

        String[] keyValue = text.split(",");

        Map<Integer, String> myMap = new HashMap<Integer, String>();
        for (int i = 0; i < keyValue.length; i++) {
            myMap.put(i, keyValue[i]);
        }

        Set keys = myMap.keySet();
        Iterator itr = keys.iterator();

        while (itr.hasNext()) {
            Integer key = (Integer) itr.next();
            String value = (String) myMap.get(key);
            System.out.println(key + " - " + value);
        }
    }
}