sorry I just started learning Java and my question is probably pretty dumb but I would like to get answers.
This is the code that I have written using eclipse ide:
package draft;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
public class Draft {
public static void main(String[] args) {
// TODO Auto-generated method stub
Map m=new LinkedHashMap();
String []arr= {"hello","piggie","piggie","piggie"};
for(String x:arr) {
if(m.containsKey(x)) {
int count=(int) m.get(x);
m.put(x, count +1);
}
else {
m.put(x,1);
}
}
System.out.println(m);
}
}
So my question is for the code m.put(x,count+1), is this equal to m.put(x,count++). I think they are the same however, Java thinks otherwise... Can someone explain what the difference is in this case? I tried to see what the variables are step by step using debug but after i set the break point and using step into function to figure out how the variables are changing, the variable count just stopped at 1...so i dont know what was going on in that loop...
thank you guys