惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
S
Securelist
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
AI
AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Schneier on Security
Schneier on Security
Attack and Defense Labs
Attack and Defense Labs
Vercel News
Vercel News
腾讯CDC
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
量子位
S
Schneier on Security
Hacker News: Ask HN
Hacker News: Ask HN
Cyberwarzone
Cyberwarzone
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
T
Tenable Blog
PCI Perspectives
PCI Perspectives
MyScale Blog
MyScale Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
W
WeLiveSecurity
N
News | PayPal Newsroom
P
Proofpoint News Feed
O
OpenAI News
C
CERT Recently Published Vulnerability Notes
B
Blog
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Spread Privacy
Spread Privacy

博客园 - cindy_zl

SAP SD销售与分销模块 Agent认知框架ReAct&Plan RAG系统优化 RAG检索优化 RAG架构 SAA-C02-架构师助理级-英文版-Q1 scala-数组 navicat mysql创建存储过程报错 安装完kali出现中文乱码 Spark SQL是处理结构化的数据 SPARK SQL ERROR: Detected cartesian product for INNER join between logical plans报错解决方法 scala的lazy关键字 scala集合三大类(seq序列,set集,map映射)——set集合 scala集合三大类(seq序列,set集,map映射)——list序列 scala元组及拉链操作 scala的map映射 scala数组 scala方法和涵数的声明以及方法转换成涵数 scala的基础数据类型&if条件表达式&for循环
scala集合三大类(seq序列,set集,map映射)——map映射
cindy_zl · 2019-09-18 · via 博客园 - cindy_zl

scala集合三大类(seq序列,set集,map映射)——map映射

map映射:

scala> import scala.collection.mutable.HashMap._

import scala.collection.mutable.HashMap._

scala> val map1 = new HashMap[String,Int]()

map1: scala.collection.mutable.HashMap[String,Int] = HashMap()

scala> map1("scala") = 1

scala> map1

res83: scala.collection.mutable.HashMap[String,Int] = HashMap(scala -> 1)

scala> map1 += (("java",2))                 //使用+=添加一个元素

res84: map1.type = HashMap(java -> 2, scala -> 1)

scala> map1

res85: scala.collection.mutable.HashMap[String,Int] = HashMap(java -> 2, scala -> 1)

scala> map1 += (("python",3),("web",4))    //添加多个元素

            ^

       warning: method += in trait Growable is deprecated (since 2.13.0): Use `++=` (addAll) instead of varargs `+=`

res86: map1.type = HashMap(python -> 3, java -> 2, web -> 4, scala -> 1)

scala> map1

res88: scala.collection.mutable.HashMap[String,Int] = HashMap(python -> 3, java -> 2, web -> 4, scala -> 1)

scala> map1 -= ("web")        //使用 -= 移除map里面的一个元素

res89: map1.type = HashMap(python -> 3, java -> 2, scala -> 1)

scala> map1.remove("java")      //移除一个元素

res90: Option[Int] = Some(2)

scala> map1.put("c++",6)      //添加一个元素 put 操作方法实现

res92: Option[Int] = None

scala> map1

res93: scala.collection.mutable.HashMap[String,Int] = HashMap(python -> 3, c++ -> 6, scala -> 1)