object CollectionDemo7 {
def main(args: Array[String]): Unit = {
//数组使用
val arr = Array("red", "blue", "yellow")
arr(0) = "white"
for(el <- arr){println(el)}
//用Seq构建List
println(Seq("red", "blue", "yellow"))
//用IndexedSeq构建Vector
println(IndexedSeq("red", "blue", "yellow"))
//构建Stream lazy集合
def inc(i: Int): Stream[Int] = Stream.cons(i, inc(i+1))
val s = inc(1)
println(s)
println(s.take(10).toList)
println(s) def addHead(i: Int): Stream[Int] = i #:: addHead(i+1)
val ss = addHead(1)
println(ss)
println(ss.take(10).toList)
println(ss) }
}

运行结果:

white
blue
yellow
List(red, blue, yellow)
Vector(red, blue, yellow)
Stream(1, ?)
List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Stream(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ?)
Stream(1, ?)
List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Stream(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ?)

Scala 学习笔记之集合(6)的更多相关文章

  1. Scala 学习笔记之集合(3)

    建立一个Java类,为了演示Java集合类型向Scala集合的转换: import java.util.ArrayList; import java.util.List; public class S ...

  2. scala学习笔记:集合

    scala> 1 to 10 res9: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7, 8, 9 ...

  3. Scala 学习笔记之集合(1)

    package com.citi.scala object CollectionDemo { def main(args: Array[String]): Unit = { /** * List */ ...

  4. Scala 学习笔记之集合(7) Option

    object CollectionDemo8 { def main(args: Array[String]): Unit = { //Option集合的使用,可以用来安全的判断null或非null,放 ...

  5. Scala 学习笔记之集合(5)

    import collection.mutable.Buffer object CollectionDemo6 { def main(args: Array[String]): Unit = { // ...

  6. Scala 学习笔记之集合(4)

    集合的模式匹配操作: object CollectionDemo5 { def main(args: Array[String]): Unit = { //集合模式匹配1 val ls = List( ...

  7. Scala 学习笔记之集合(9) 集合常用操作汇总

    object CollectionDemo10 { def main(args: Array[String]): Unit = { var ls = List[Int](1, 2, 3) //向后增加 ...

  8. Scala 学习笔记之集合(8) Try和Future

    import util._ import concurrent.ExecutionContext.Implicits.global import concurrent.Future import co ...

  9. Scala 学习笔记之集合(2)

    class StudentTT extends StudentT{ def sayBye(name: String, age: Int)(address: String){ println(" ...

随机推荐

  1. POJ 1797-Heavy Transportation-dijkstra小变形和POJ2253类似

    传送门:http://poj.org/problem?id=1797 题意: 在起点和终点间找到一条路,使得经过的边的最小值是最大的: 和POJ2253类似,传送门:http://www.cnblog ...

  2. poj 2649 Factovisors 对n!进行因数分解

    Factovisors Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4431   Accepted: 1086 Descr ...

  3. gulp的介绍和手动安装

    gulp, 前端自动化工具, 文件操作, 项目上线之前,将碎片文件合并,将ES6转成ES5,文件压缩,快速搭建服务器... gulp基于node环境 gulp就是node的一个非内置的小模块 gulp ...

  4. android CTS 命令

    > h //help Host:  help: show this message  help all: show the complete tradefed help  exit: grace ...

  5. vue2.0 创建项目

    准备 安装淘宝 npm镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org 添加系统变量path的内容 因为cnpm会被安 ...

  6. android 屏幕切换

    1.将Activity固定位竖屏可以在配置文件这么写 <activity android:screenOrientation="portrait"> 横屏显示: < ...

  7. Google 官方 侧滑 drawerlayout

    一.概述 目前侧滑框架已经很多了,但是我常用的也就那么2个 ,slidingmenu 和sidemenu-android, 但是项目要求使用官方的,所以就看了一下drawerlayout 二.代码 官 ...

  8. android端 版本升级

    由于项目中要求实现版本升级,特写此代码,有因为这段代码基本都是通用,所以记录下来,以便下次直接拷贝... public class ApkVersionUpdate { /** apk文件下载状态:正 ...

  9. hadoop 通过distcp进行并行复制

    通过distcp进行并行复制 前面的HDFS访问模型都集中于单线程的访问.例如通过指定文件通配,我们可以对一部分文件进行处理,但是为了高效,对这些文件的并行处理需要新写一个程序.Hadoop有一个叫d ...

  10. STL中nth_element的用法

    nth_element函数原型有四个,详细我就不一一累赘了,我们就用最普通的用法寻找第k位置的元素. 函数用法为:nth_element(first,kth,end). first,last 第一个和 ...