Fast way to load all alphabetic characters to a hashmap
Use double brace initialization. It's very compact and helpful in initializing collections.
Map<String, Integer> map = new HashMap<String, Integer>() {
{
for (char ch = 'A'; ch <= 'Z'; ++ch)
put(String.valueOf(ch), 0);
}
};
Note that - put method is called without the map reference.
Do it in for loop:
for (char ch = 'A'; ch <= 'Z'; ++ch)
map.put(String.valueOf(ch), 0);