Is there any difference between this code:
for(term <- term_array) {
val list = hashmap.get(term)
...
}
and:
Instantiating variables inside for loops makes sense if you want to use that variable the for
statement, like:
for (i <- is; a = something; if (a)) {
...
}
And the reason why your list is outdated, is that this translates to a foreach
call, such as:
term_array.foreach {
term => val list= hashmap.get(term)
} foreach {
...
}
So when you reach ..., your hashmap has already been changed. The other example translates to:
term_array.foreach {
term => val list= hashmap.get(term)
...
}