scala> val data = new Array[String](3);
scala> data(0) = "lady gaga"
scala> data(1) = "luna maya"
scala> data(2) = "aura kasih"
To access an element, use ( ) operator, not [ ], with the index:
scala> println(data(0));
To iterate to the whole elements, use:
scala> for ( d <- data){
| println(d);
| }
or
scala> data.foreach(println);
lady gaga
luna maya
aura kasih
No comments:
Post a Comment