def demoVar(): Unit ={
println("---var---")
var list = new ListBuffer[Int]
list += 1
list += 3
list += 5
println(list)
}
Scala 迭代器
方法,遍历集合
objectIteratorDemo {def main(args: Array[String]): Unit = {
val list = List(1, 2, 3, 5)
val i = list.iterator
while (i.hasNext) {
println(i.next())
}
println("---")
val ri = list.reverseIterator //反向遍历while (ri.hasNext) {
println(ri.next())
}
}
}