0

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

1
  • "index wise" what does it mean? Commented Jan 28, 2020 at 18:02

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.