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

推荐订阅源

博客园_首页
C
Cyber Attacks, Cyber Crime and Cyber Security
GbyAI
GbyAI
V
V2EX
M
MIT News - Artificial intelligence
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
小众软件
小众软件
量子位
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
H
Help Net Security
Y
Y Combinator Blog
博客园 - 三生石上(FineUI控件)
人人都是产品经理
人人都是产品经理
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
爱范儿
爱范儿
雷峰网
雷峰网
博客园 - 叶小钗
宝玉的分享
宝玉的分享
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
D
DataBreaches.Net
PCI Perspectives
PCI Perspectives
Martin Fowler
Martin Fowler
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Proofpoint News Feed
T
Threatpost
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
O
OpenAI News
Latest news
Latest news
Hugging Face - Blog
Hugging Face - Blog
云风的 BLOG
云风的 BLOG
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Attack and Defense Labs
Attack and Defense Labs
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
Help Net Security
Help Net Security
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Microsoft Security Blog
Microsoft Security Blog
H
Heimdal Security Blog
N
Netflix TechBlog - Medium
L
LINUX DO - 最新话题
C
Check Point Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tailwind CSS Blog
Scott Helme
Scott Helme

博客园 - 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)