欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Scala Range与Stream

程序员文章站 2022-05-15 19:22:20
...

一 Range

  1. scala>1 to 10
  2. res20: scala.collection.immutable.Range.Inclusive=Range1 to 10
  3. scala>1 to 10 by 2
  4. res21: scala.collection.immutable.Range= inexact Range1 to 10 by 2
  5. scala>(1 to 10).toList
  6. res22:List[Int]=List(1,2,3,4,5,6,7,8,9,10)
  7. scala>1 until 10
  8. res23: scala.collection.immutable.Range=Range1 until 10
二 Stream
  1. scala>1#::2 #::3 #::Stream.empty
  2. res24: scala.collection.immutable.Stream[Int]=Stream(1,?)
  3. scala> val stream =(1 to 100000).toStream
  4. stream: scala.collection.immutable.Stream[Int]=Stream(1,?)
  5. scala> stream.head
  6. res25:Int=1
  7. scala> stream.tail
  8. res26: scala.collection.immutable.Stream[Int]=Stream(2,?)
相关标签: Scala Range Stream