I have a Map<String, Integer>
and an integer named globalValue. My goal is to replace values in map with percentage of globalValue, eg; (value1/globalValue)*100 and round the final number.
I have tried doing division directly in the map (which resulted in 0) and also trying to convert my integers to double both in the map and outside the map (both resulted in type mismatch).
public Map<String, Integer> analyse() {
int globalValue = 0;
Map<String, Integer> m = new HashMap<String, Integer>();
for (int i = 0; i < array.length; i++) {
if (array[i].getTime() != null) {
globalValue = globalValue + array[i].getValue();
if (m.containsKey(array[i].getTime())) {
m.put(array[i].getTime(), m.get(array[i].getTime()) + array[i].getValue());
} else {
m.put(array[i].getTime(), array[i].getValue());
}
}
}
return m;
}