please use Map.Entry iterator since you need both key and value:

for (Map.Entry<String, Long> e: totals.entrySet()) {
...
}