Reputation: 11
i want to insert values in mutable list index wise using for loop as following
var firstList=List("A","B","C","D")
var newList = new ListBuffer[String]()
for(i<-0 to firstList.length-1){
**newList(i)**=firstList(i)
}
i want to do similar task.. I know how to insert values using " newList+=firstList(i) " this method, but i want this with index wise approach
Upvotes: 0
Views: 151
Reputation: 66
Use def insert(n: Int, elems: A*) method in scala.collection.mutable.ArrayBuffer https://www.scala-lang.org/api/current/scala/collection/mutable/ArrayBuffer.html
Upvotes: 1