In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Good programmer big data learning route sharing Scala series of mapping Map first let's take a look at what is map in Scala, the hash table this data structure is called mapping.
1. In Scala, there are two kinds of Map, one is the Map under the immutable package, the content of the Map is immutable, and the other is the Map under the mutable package, the content of the Map is changeable.
Build an immutable map
Build using tuples
Build a mutable map
two。 To get and modify the values in the mapping, there are three ways to obtain the corresponding values in map according to the key. In particular, the getOrElse method is recommended.
Modify variable map information to traverse access map
Object MappingDemo {
Def main (args: Array [String]): Unit = {
/ / define to build a mutable map
Val scores = scala.collection.mutable.Map ("zhangsan"-> 90, "lisi"-> 80, "wangwu"-> 0)
/ / val scores2 = scala.collection.mutable.Map ("moumou"-> 50)
/ / modify the value of the corresponding key in map
Scores ("wangwu") = 100
/ / add a new key value to map
Scores ("zhaoliu") = 50 / / similar to scores.update ("zhangsan", 50)
Scores + = ("sunqi"-> 60, "qianba"-> 99)
/ / scores + + = scores2
/ / remove a key-value pair
Scores-= "zhangsan" / / similar to scores.remove ("zhangsan")
/ / scores-- = scores2 doesn't work?
/ / get the set merge traversal of the key
/ / it doesn't mean much? How to get a value by building
Val res = scores.keySet
For (elem
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
Rely on org.springframework.boot spring-boot-starter-data-jpa
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.