Iterable 是序列(Seq), 集(Set) 映射(Map)的特质

序列式有序的集合如数组和列表

集合可以通过== 方法确定对每个对象最多包含一个

映射包含了键值映射关系的集合

列表缓存:

  使用ListBuffer代替List 另一个理由是为了避免栈溢出的风险

数组缓存: ArrayBuffer需要先从可变集合包引用 scala.collection.mutable.ArrayBuffer

  val buf = new ArrayBuffer[Int]()

队列Queue:先进先出

class BankAccount {
private var bal: Int = 0
def balance: Int = bal
def deposit(account: Int){
require(account > 0)
bal += account
}
def widthDraw(account: Int): Boolean = {
if (account > bal ) false
else {bal -= account
true }
}
}
abstract  class Simulation {
type Action = {} => Unit
case class WorkItem(time: Int, action: Action)
private var currtime = 0
def currentTime: Int = currtime private var agenda: List[WorkItem] = List()
private def insert(arg: List[WorkItem],
item: WorkItem) : List[WorkItem] = {
if (arg.isEmpty || item.time < arg.head.time) item :: arg
else arg.head :: insert(arg.tail, item)
}
def afterDelay(delay: Int)(block: => Unit) = {
/* val item = WorkItem(currentTime + delay, { } => block)
agenda = insert(agenda, item )*/
} private def next(){
(agenda: @unchecked) match{
case item:: rest =>
agenda = rest
currtime = item.time
item.action()
}
}
def run(){
afterDelay(0){
println("*** sim start... time = + currentTime +***")
}
// while (!agenda.isEmpty) next()
}
}
class Time {
private[tjis] var h = 12
private[this] var n = {}
def hour: Int = h
def hour_ = (x: Int) {h = x}
def minute: Int = m
def minute_ = (x: Int) {m = x} }
class scala {

}
object scala{
def main(args: Array[String]) {
System.out.println("HelloWorld")
}
def isort(sx: List[Int]): List[Int] = {
if (sx.isEmpty) Nil else isinsert(sx.head, isort(sx.tail))
} def isinsert(ss: Int,sx: List[Int]) : List[Int] = {
if (sx.isEmpty || ss <= sx.head) ss :: sx else sx.head :: isinsert(ss, sx.tail)
}
// 以下使用模式匹配
def isort2(sx: List[Int]) : List[Int] = sx match {
case List() => List()
case x :: sxl => insert2(x, isort2(sxl))
} def insert2(x: Int, xs: List[Int]): List[Int] = xs match {
case List() => List(x)
case y :: ys => if (x <= y) x:: xs else y :: insert2(x, ys)
} def append1[T](sx: List[T], ys: List[T]) : List[T] ={
sx match {
case List() => ys
// case x :: sxl => x :: append1(sxl, ys)
}
}
//队列
val queue1 = new mutable.Queue[Int]
val va1 = queue1.enqueue(1) // 不可变队列添加元素用enQueue
val queue = new mutable.Queue[String]
queue += "a"
queue ++= List("b", "c") //有序的
val ts = mutable.TreeSet(2,4,6,7,0,8,3)
def mapMaker: Map[String, String] = {
new HashMap[String, String] with
SynchronizedMap[String, String] {
// override def default1(key: String) = " hellon word"
}
}
}

scala 集合类型的更多相关文章

  1. Scala集合类型详解

    Scala集合 Scala提供了一套很好的集合实现,提供了一些集合类型的抽象. Scala 集合分为可变的和不可变的集合. 可变集合可以在适当的地方被更新或扩展.这意味着你可以修改,添加,移除一个集合 ...

  2. Scala学习笔记--集合类型Queue,Set

    补充知识:http://www.importnew.com/4543.html 正文开始 scala.collection.immutable scala.collection.mutable 队列Q ...

  3. Programming In Scala笔记-第十七章、Scala中的集合类型

    本章主要介绍Scala中的集合类型,主要包括:Array, ListBuffer, Arraybuffer, Set, Map和Tuple. 一.序列 序列类型的对象中包含多个按顺序排列好的元素,可以 ...

  4. Scala:集合类型Collection和迭代器

    http://blog.csdn.net/pipisorry/article/details/52902549 Scala Collection Scala 集合分为可变的和不可变的集合. 可变集合可 ...

  5. [转] Scala 的集合类型与数组操作

    [From] https://blog.csdn.net/gongxifacai_believe/article/details/81916659 版权声明:本文为博主原创文章,转载请注明出处. ht ...

  6. Scala 学习之路(五)—— 集合类型综述

    一.集合简介 Scala中拥有多种集合类型,主要分为可变的和不可变的集合两大类: 可变集合: 可以被修改.即可以更改,添加,删除集合中的元素: 不可变集合类:不能被修改.对集合执行更改,添加或删除操作 ...

  7. Scala 系列(五)—— 集合类型综述

    一.集合简介 Scala中拥有多种集合类型,主要分为可变的和不可变的集合两大类: 可变集合: 可以被修改.即可以更改,添加,删除集合中的元素: 不可变集合类:不能被修改.对集合执行更改,添加或删除操作 ...

  8. Scala集合操作

    大数据技术是数据的集合以及对数据集合的操作技术的统称,具体来说: 1.数据集合:会涉及数据的搜集.存储等,搜集会有很多技术,存储技术现在比较经典方案是使用Hadoop,不过也很多方案采用Kafka.  ...

  9. scala集合

    优先使用不可变集合.不可变集合适用于大多数情况,让程序易于理解和推断,因为它们是引用透明的( referentially transparent )因此缺省也是线程安全的. 使用可变集合时,明确地引用 ...

随机推荐

  1. TTL 与 CMOS

    Frm: https://blog.csdn.net/qq_27745395/article/details/76687175 http://baijiahao.baidu.com/s?id=1598 ...

  2. yum安装apache

    一.查询是否已经安装apache rpm  -qa  httpd 注:Apache在linux系统里的名字是httpd 如果有返回的信息,则会显示已经安装的软件.如果没有则不会显示其它的信息.如下图是 ...

  3. 第四周总结和实验二Java简单类与对象

    实验目的 掌握类的定义,熟悉属性.构造函数.方法的使用,掌握用类作为类型声明变量和方法返回值: 理解类和对象的区别,掌握构造函数的使用,熟悉通过对象名引用实列的方法和属性: 理解static修饰对类. ...

  4. Windows XP 下如何使用Qt Creator中的Git版本控制功能

     原文地址:http://www.qtcn.org/bbs/simple/?t16960.html Qt Creator是针对Qt应用开发平台专门设计的IDE开发工具,集成了很多功能,分别有win ...

  5. LLppdd has a dream!

    LLppdd has a dream Time Limit: 3 s Memory Limit: 256 MB 题目背景 LLppdd经过他充满坎坷的初三后,他的成绩也充满了坎坷. 临近中考了,他希望 ...

  6. linux 命令 - man, help, info(查看命令帮助手册)

    man, help, info - 查看命令帮助手册   help xxx  # 显示内置命令帮助信息: xxx --help  # 显示外置命令帮助信息: man xxx  # 没有内建与外部命令的 ...

  7. linux netstat 统计连接数查看外部(转)

    转自:http://boy-liguang.blog.sohu.com/187052443.html linux netstat 统计连接数查看外部 2011-10-11 08:52阅读(16333) ...

  8. java笔试题大全之IO流常见选择题

    1.下面哪个流类属于面向字符的输入流()选择一项)A. BufferedWriterB. FileInputStreamC. ObjectInputStreamD. InputStreamReader ...

  9. QDomDocument::clear()的调用,会导致关闭程序时崩溃!!!

    //读一份xml前,先清理m_Doc[QDomDocument] bool XmlIO::xmlRead(QString &errmsg) { m_mutex.lock(); // m_Doc ...

  10. Vue学习笔记【17】——配置本地数据库和数据接口API

    先解压安装 PHPStudy; 解压安装 Navicat 这个数据库可视化工具,并激活: 打开 Navicat 工具,新建空白数据库,名为 dtcmsdb4; 双击新建的数据库,连接上这个空白数据库, ...