I have an ArrayBuffer of Strings as below:
var myList = ArrayBuffer[String]()
myList += "abc"
myList += "def"
Now, I'm trying to update the String in the ArrayBuffer based on some condition:
for(item <- myList){
if(some condition){
item = "updatedstring"
}
}
When I try to do this, I get an error saying val cannot be reassigned. Why do I get this error even though I have declared myList as a var? If I cannot update it this way, how else can I update the elements when iterating through the ArrayBuffer? I'm new to Scala, so I apologize if I got this all wrong.