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. 运维 03 Linux之文档与目录结构

    Linux之文档与目录结构   Linux文件系统结构 Linux目录结构的组织形式和Windows有很大的不同.首先Linux没有“盘(C盘.D盘.E盘)”的概念.已经建立文件系统的硬盘分区被挂载到 ...

  2. 三、函数 (SUM、MIN、MAX、COUNT、AVG)

    第八章 使用数据处理函数 8.1 函数 SQL支持利用函数来处理数据.函数一般是在数据上执行的,给数据的转换和处理提供了方便. 每一个DBMS都有特定的函数.只有少数几个函数被所有主要的DBMS等同的 ...

  3. 使用apache搭建tomcat集群

    1.安装apache 1.1 下载ApacheX64.rar,并解压 1.2 修改Apache24\conf\httpd.conf文件 配置根目录: 配置ip和端口 1.2 安装apache服务器 以 ...

  4. 函数节流及手机端点击延迟200ms解决方法

    不论是H5开发还是微信小程序,手机端点击都会有300ms的延迟,在实际项目中,会到此频繁触发,如有接口会频繁的请求接口,除了会引起不必要的多次请求还会导致数据有问题.下面有二种方式来处理这个问题: 1 ...

  5. Elastic-Job分布式任务调度

    任务调度是指系统为了自动完成特定任务,在约定的特定时刻去执行任务的过程,有了任务调度即可解放更多的人力由系统自动去执行任务. 多线程方式实现: Timer方式实现: ScheduledExecutor ...

  6. Angular 4 变更检测机制 ChangeDetectorRef 使用方法

    1.在angular 2中,回调函数的返回结果,不会自动更新视图层的显示,可以用 ChangeDetectorRef 来驱动angular更新视图. import {ChangeDetectorRef ...

  7. 杭电多校第六场-J-Ridiculous Netizens

    Problem Description Mr. Bread has a tree T with n vertices, labeled by 1,2,…,n. Each vertex of the t ...

  8. icomoon字体图标引用代码

    1.第一步在样式里声明字体:告诉别人我们自己定义的字体. @font-face{ /*声明字体 引用字体*/ font-family:'icomoon'; src:url('fonts/icomoon ...

  9. Windows——关于Word2016/2019提示需要修复问题处理

    一.问题描述 打开Word提示 很抱歉此功能看似已中断,并需要修复.请使用Windows控制面板中的“程序和功能”选项修复Microsoft Office. 二.解决方法 运行 regedit 进入注 ...

  10. 【leetcode】962. Maximum Width Ramp

    题目如下: Given an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j]. ...