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. 如何在webpack开发中利用vue框架使用ES6中提供的新语法

    在webpack中开发,会遇到一大推问题,特别是babel6升级到babel7,要跟新一大推插件,而对于安装babel的功能就是在webpack开发中,vue中能够是用ES6的新特性: 例如ES6中的 ...

  2. 树的重心(DFS)

    ;vector< ; i < v[node].size() ; i++){ , ; i <= n- ; i++){ cin >> a >> b; v[a].p ...

  3. jmeter 不同线程组之间传递变量3

    jemter编写脚本要点: 1.切记:BeanShell PostProcessor写在关联函数 Regular Expression Extractor的后面 2.header  HTTP Head ...

  4. Zabbix Server 和 Zabbix Agentd 开机自动运行

    Zabbix Server 和 Zabbix Agentd 开机自动运行 请问:怎样 Zabbix Server 和 Zabbix Agentd 开机自动运行? 注:如果你的命令行写进了 /etc/r ...

  5. python-模块 time, os, sys

    时间模块 和时间有关系的我们就要用到时间模块.在使用模块之前,应该首先导入这个模块. #常用方法 1.time.sleep(secs) (线程)推迟指定的时间运行.单位为秒. 2.time.time( ...

  6. 破解Pycharm 2019.2

    参考:https://www.cnblogs.com/pig66/p/11432446.html 1.下载补丁文件 https://pan.baidu.com/s/112tS3XjAENIHaJ-aS ...

  7. vue对象侦测

    http://blog.csdn.net/yihanzhi/article/details/74200618 数组:this.$set(this.arr,index,value)

  8. Win7下设置一键关闭所有程序的功能

    (文章仅作个人整理和笔记) 在很多情况下,上班族发生这种情况的比较多吧,忙碌的一天下来,准备下班走人的时候,发现自己的电脑打开了好多程序,需要一个一个去关闭,那么有没有什么方法可以实现一键快速关闭所有 ...

  9. Javafx弹窗

    在javafx中可能用到一些弹窗,比如点击某个按钮后弹出弹窗提示信息等等 Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle( ...

  10. java获取网页源代码并写入本地文件中

    import java.io.*; import java.net.*; public class URLDemo { public static void main(String args[]){ ...