Can anyone explain the logic behind this code?

The code below inserts the values in my HashMap named map2 even before I use the put function to insert the array using the specific key. I tried commenting the last line and it works even without it. Can anyone explain what happening in this code?

public static int findshortestLength(int input[]) {
        HashMap<Integer,Integer> map = new HashMap<>();
        HashMap<Integer,Integer[]> map2 =new HashMap<>();
        int max = 0;
        for(int i=0;i<input.length;i++) {
            map.put(input[i], map.getOrDefault(input[i],0)+1);
            max = Math.max(max, map.get(input[i]));
            if(map2.get(input[i])==null) map2.put(input[i], new Integer[2]);
            Integer[] tempRange = map2.get(input[i]);
            if(tempRange[0]==null) tempRange[0] = i;
            tempRange[1] = i;
            //map2.put(input[i],tempRange); Same result using this line