object TestScala {
def main(args: Array[String]): Unit = {
val mainList = List(3, 2, 1)
mainList.patch(1, Seq(5), 0)
println("mainList-->"+mainList)
}
}
The output is mainList-->List(3, 2, 1) not expected one
I am expecting 3,5,2,1
Scala List is immutable. Assign it to variable and it will produce desired output.
object TestScala {
def main(args: Array[String]): Unit = {
var mainList = List(3, 2, 1)
mainList = mainList.patch(1, Seq(5), 0)
println("mainList-->"+mainList)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With