I want to make a histogram by using a HashMap
, the key should be the delay, the value the amount of times this delay occurs. I am doubting to use the HashMap
replace
or the HashMap
put
function if an already existing delay has an new occurence. I did it by this way:
int delay = (int) (loopcount-packetServed.getArrivalTime());
if(histogramType1.containsKey(delay)) {
histogramType1.replace(delay, histogramType1.get(delay) + 1);
} else {
histogramType1.put(delay, 1);
}
Is this correct? or should I use two times the put function?
See Question&Answers more detail:os