color.java Source code

Java tutorial

Introduction

Here is the source code for color.java

Source

import java.util.EnumMap;
import java.util.Map;

enum color {
    red, green, blue
}

enum letter {
    a, b, c
}

public class Main {
    public static void main(String[] args) {
        Map<color, letter> map = new EnumMap<color, letter>(color.class);

        map.put(color.red, letter.a);
        map.put(color.green, letter.b);
        map.put(color.blue, letter.c);

        Map<color, letter> map2 = new EnumMap<color, letter>(color.class);
        letter[] letters = new letter[] { letter.a, letter.b, letter.c };

        for (int i = 0; i < color.values().length; i++) {
            map2.put(color.values()[i], letters[i]);
        }
        System.out.println(map);
        System.out.println(map2);
    }

}