In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the explanation of Scala basic Map mapping". In the daily operation, I believe that many people have doubts about the explanation of Scala basic Map mapping. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "Scala basic Map mapping explanation". Next, please follow the editor to study!
# # Map
A Scala map (Map) is an object with a set of key / value pairs. The key is unique in the mapping, but the value is not necessarily unique. Mapping is also known as a hash table. There are two kinds of mappings, immutable and mutable. By default, Scala uses immutable mapping (Map). If you want to use mutable collections (Map), you need to explicitly import the scala.collection.mutable.Map class
Val map = Map ("name"-> "xiaoming", "age"-> 20) println (map ("name"))
To declare an empty mapping, you cannot omit the type description, add a key-value pair to the mapping (Map), and use the operator +
Var m: Map [String,Int] = Map () m + = ("one"-> 1)
To determine whether a value is included in the map, you can use the contains method
If (map.contains ("age")) {println (map ("age"))}
If you need to create a variable mapping, you need to introduce the scala.collection.mutable.Map package, otherwise value update is not a member of scala.collection.immutable.Map [String,Any] map ("gender") = "cumputer"
Val map = Map ("name"-> "xiaoming", "age"-> 20) map ("gender") = "cumputer" println (map ("gender")
Traversing map
Val map = Map ("name"-> "xiaoming", "age"-> 20) map ("gender") = "cumputer" for ((kmemv)
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.