Why after updating Array element I still get old array values?

37 views
Skip to first unread message

Sebastian M Cheung

unread,
Jul 23, 2015, 3:15:05 PM7/23/15
to scala-language
Why after updating Array element I still get old array values?


var compactWay = Array("I", "like", "this", "way")
>compactWay: Array[String] = Array(I, like, this, way)

compactWay(0) = "We"
println(compactWay.mkString(" "))
>We like this way res3: Unit = ()

var secondList = Array("Something else")
var thirdList = compactWay++secondList
>thirdList: Array[String] = Array(I, like, this, way, Something else)
(expecting to see Array(We, like, this, way, Something else)

Oliver Ruebenacker

unread,
Jul 23, 2015, 3:20:35 PM7/23/15
to scala-l...@googlegroups.com

     Hello,

  Strange - works as expected for me:

Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_79).
Type in expressions to have them evaluated.
Type :help for more information.

scala> var compactWay = Array("I", "like", "this", "way")

compactWay: Array[String] = Array(I, like, this, way)

scala> compactWay(0) = "We"

scala> println(compactWay.mkString(" "))
We like this way

scala> var secondList = Array("Something else")
secondList: Array[String] = Array(Something else)

scala> var thirdList = compactWay++secondList
thirdList: Array[String] = Array(We, like, this, way, Something else)

     Best, Oliver

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

Reply all
Reply to author
Forward
0 new messages