Java Code Example: HashMap alphabet

The following program outputs the position of certain letters in the alphabet.

import java.util.HashMap;

public class Cube {
    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        map.put("A", "1");
        map.put("B", "2");
        map.put("G", "7");
        map.put("M", "13");

        map.forEach((key, value) -> {
            System.out.printf("%s is the %s letter in alphabet\n", key, value);
A is the 1 letter in alphabet
B is the 2 letter in alphabet
G is the 7 letter in alphabet
M is the 13 letter in alphabet