Howdy, Stranger!

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


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

Damian99Damian99 USAMember Posts: 116

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



  • DavidMDavidM USAMember Posts: 342
    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.