What is the best way to Initialise a static Map in Java - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

What is the best way to Initialise a static Map in Java

Damian99Damian99 USAPosts: 116Member

Can someone please let me know the best(only) way to initialize a Static Map in Java?

Tagged:

Comments

  • DavidMDavidM USAPosts: 342Member
    public class Test {
        private static final Map<Integer, String> myMap;
        static {
            Map<Integer, String> aMap = ....;
            aMap.put(1, "one");
            aMap.put(2, "two");
            myMap = Collections.unmodifiableMap(aMap);
        }
    }
    
Sign In or Register to comment.