scala> val data = List("lady gaga","barack obama","larry page")
To access an element of list, use its index:
scala> println(data(2))
larry page
To iterate the whole elements, use:
scala> for( d <- data){
| println(d)
| }or
scala> data.foreach(println);lady gaga
barack obama
larry page
To know what the size, use:
scala> data.length
To get the first element, use:
scala> data.head
To get the last element, use:
scala> data.last
To reverse the elements order, use:
scala> data.reverse
No comments:
Post a Comment