Q:

Isn't Integer a reference? Why doesnt an inc not update a hashmap value?

I was expecting that the following snippets are equivalent:  
Integer count = occurences.get(c);  
if(count == null) {  
   count = 0;  
   occurences.put(c, count);   
}  
++count;  

and  
Integer count = occurences.get(c);  
if(count == null) {  
    count = 0;  
    occurences.put(c, count);  
}  
occurences.put(c, count + 1);  

But when I run the program the first snippet always has the count as 0.
Why is that? Since Integer is a reference in the HashMap why isn't the increment reflected and I need to do a put?

A:

count is a local variable. It points to an instance of an immutable class, Integer.
When you increment it with:
++count;

that's just syntactic sugar for:
count = Integer.valueOf(count.intValue() + 1);

You're reassigning count. That's all.

