I have a listbuffer of events Animals. I am trying to update one of those properties.However, when using update it updates the whole element. Is there a way to update a particualr property? I'd want to update the owner for example.
import java.util.UUID
case class Car(model: String, owner: String)
var cars = new scala.collection.mutable.ListBuffer[Car]()
var car1 = Car("honda", "John")
var car2 = Car("chevy", "Xavier")
var car3 = Car("subaru", "Mario")
cars += car1
cars += car2
cars += car3
def generateRandomGuid(numOfTenants: Int) = {
List.tabulate(numOfTenants)(_ => UUID.randomUUID().toString())
}
val ownerList = generateRandomGuid(3)
for(newowner <- ownerList) {
for(eventIdx <- 0 to cars.length-1) {
//cars.update(eventIdx, newowner)
cars(eventIdx).owner = newowner
}
}
Update1:
updated to using var for the different cars and the list buffer to Car however, i still cannot reassign because error: reassignment to val cars(eventIdx).owner = newowner
ListBuffer(which should be aListBuffer[Car], btw). You'd have to markownerwithvar, and then you can docars(eventIdx).owner = newOwnerval