I have a RDD named countSumMeanVariance2 with type structure is like this:
("Key", (4, 123, 30.75, 2.06))
I want to keep track the last 2 values: _._2._3 and _._2._4 by updating them into HashMap variables (since I will run a for loop and change those values every time).
What I am currently doing to update HashMaps is like below:
val meanHashMap = scala.collection.mutable.Map[String,Float]();
for (c <- countSumMeanVariance2) {
meanHashMap.update(c._1, c._2._3);
println("c._1: " + c._1);
println("c._2._3: " + c._2._3);
println("meanHashMap(c._1): " + meanHashMap(c._1));
println("meanHashMap size: " + meanHashMap.size);
}
println("meanHashMap size after for: " + meanHashMap.size);
What I found so weird is after the loop, the HashMap does not persist values. The println inside the loop can tell updated hashmap's size, but the println after the loop shows the size is set back to zero.
...
c._1: "GEORGIA"
c._2._3: 53.6605
meanHashMap(c._1): 53.6605
meanHashMap size: 46
c._1: "VIRGINIA"
c._2._3: 55.478752
meanHashMap(c._1): 55.478752
meanHashMap size: 47
c._1: "ILLINOIS"
c._2._3: 154.02426
meanHashMap(c._1): 154.02426
meanHashMap size: 48
meanHashMap size after for: 0
Anyone know it why? can you help to explain to me and suggest the way it should work to update hashmap's values?