Friday, July 6, 2012

How to Initialise a static Map in Java

private static final Map<String, String> channelTypes =
    new HashMap<String, String>();
static {
        channelTypes.put("I", "Incremental");
        channelTypes.put("N", "Instrument");
        channelTypes.put("S", "Snapshot");
}

private static final Map<String, String> channelTypes =
     new HashMap<String, String>() {
     {
                    put("I", "Incremental");
                    put("N", "Instrument");
                    put("S", "Snapshot");
      }
};

No comments: