I have a section of code like this:
Map<Integer, Map<Integer, Integer>> hashMap = new HashMap<>();
for (int[] time : times) {
if (!hashMap.containsKey(time[0])) {
hashMap.put(time[0], new HashMap<Integer, Integer>());
}
hashMap.get(time[0]).put(time[1], time[2]);
}
Inside this code, time
is an array with 3 elements (e.g [0, 1, 2]), and times
is made up of such array. I first stored elements like this but when I access the map later, it throws a NullPointerException
. Does it mean that the map actually stores nothing?