scala hashmap_如何在Scala中將Hashmap轉換為Map?

scala hashmap

Let's first understand what are maps and hashmaps?

首先讓我們了解什么是maphashmap

map in Scala is a collection that stores its elements as key-value pairs, like a dictionary.

Scala中的map是一個集合,將其元素存儲為鍵值對,例如字典。

Example:

例:

Map( 1 -> Scala, 2 -> Python, 3 -> Javascript) 

hashmap is a collection based on maps and hashes. It stores key-value pairs.

hashmap是基于映射和哈希的集合。 它存儲鍵值對。

Example:

例:

HashMap( 1 -> Scala, 2 -> Python, 3 -> Javascript) 

將HashMap轉換為Map (Converting HashMap to Map)

In Scala, we can convert a hashmap to a map using the tomap method.

在Scala中,我們可以使用tomap方法將哈希圖轉換為地圖。

Syntax:

句法:

Map = HashMap.toMap

Scala program to convert hashmap to map

Scala程序將hashmap轉換為map

import scala.collection.mutable.HashMap ;
object MyClass {
def main(args: Array[String]) {
val hashMap = HashMap(1->"Scala", 2->"Python", 3->"JavaScript")
println("HashMap: " + hashMap)
val map = hashMap.toMap
println("Map: " + map)
}
}

Output:

輸出:

HashMap: HashMap(1 -> Scala, 2 -> Python, 3 -> JavaScript)
Map: Map(1 -> Scala, 2 -> Python, 3 -> JavaScript)

Explanation:

說明:

In the above code, we have created a HashMap and then convert it to a Map using the toMap method.

在上面的代碼中,我們創建了一個HashMap,然后使用toMap方法將其轉換為Map。

翻譯自: https://www.includehelp.com/scala/convert-hashmap-to-map.aspx

scala hashmap

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377658.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377658.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377658.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

十二、所有功能實現效果演示

一、系統項目架構 Ⅰ,fiber_yy數據庫下有五張表 yy_admin:管理員登錄賬號和密碼 yy_textile:紡織面料數據信息 yy_textile_record:用戶購買紡織面料信息所存儲的面料流水信息 yy_user:用戶登錄注冊信息 yy_user_reco…

行業軟件之PTV微觀軟件VISSIM4.3 5.0 5.1 5.2 5.3 5.4下載和相關資料

他是干什么的:http://baike.baidu.com/view/3656765.htm 中國代理銷售的公司的網址:辟途威交通科技(上海)有限公司 官網:http://www.ptvchina.cn/ 看看視頻中軟件的運行效果:http://v.youku.com/v_show/id_XMzExMjg1MDEy.html 如何…

一、單個神經元網絡構建

一、本人使用編譯器為Jupyter Notebook,tensorflow版本為1.13.1 import tensorflow as tf print(tf.__version__) """ 1.13.1 """二、訓練單個神經元網絡 x為-1.0, 0.0, 1.0, 2.0, 3.0, 4.0 y為-3.0, -1.0, 1.0, 3.0, 5.0, 7.0 人用…

ruby 生成隨機字符串_Ruby程序生成隨機數

ruby 生成隨機字符串產生隨機數 (Generating random number) The task is to generate and print random number. 任務是生成并打印隨機數。 Generating random numbers means that any number can be provided to you which is not dependent on any pre-specified condition…

leetcode 322. 零錢兌換 思考分析

目錄1、題目2、思路分析3、參考鏈接1、題目 給定不同面額的硬幣 coins 和一個總金額 amount。編寫一個函數來計算可以湊成總金額所需的最少的硬幣個數。如果沒有任何一種硬幣組合能組成總金額,返回 -1。 你可以認為每種硬幣的數量是無限的。 提示: 1 …

linux上的英文字體monospace可以在windows用嗎?

linux的字體都是開源的,應該可以官方下載本地下載轉載于:https://www.cnblogs.com/52linux/archive/2012/03/14/2396103.html

Flash Builder 創建CSS

1.global 選擇器將樣式應用于所有控件 在 Flash Builder 中創建新MXML 文件并切換到設計模式 屬性視圖右側的外觀視圖可更改外觀 Flash Builder 自動創建CSS 文件 CSS 文件有2 個命名空間: s 指 Spark 組件 mx 指 MX 組件 1. Global 與Application 選擇器 global …

ruby打印_Ruby程序打印數字的力量

ruby打印Ruby中數字的冪 (Power of a number in Ruby) The task to develop a program that prints power of a number in Ruby programming language. 開發可以用Ruby編程語言打印數字冪的程序的任務。 If we want to calculate the power of a number manually then we have…

二、訓練fashion_mnist數據集

一、加載fashion_mnist數據集 fashion_mnist數據集中數據為28*28大小的10分類衣物數據集 其中訓練集60000張,測試集10000張 from tensorflow import keras import tensorflow as tf import matplotlib.pyplot as plt import numpy as npfashion_mnist keras.data…

jquerymobile 切換頁面時候閃爍問題

https://github.com/jquery/jquery-mobile/commit/acbec71e29b6acec6cd2087e84e8434fecc0053f 可以修改css好像是個bug -4,9 4,10 * Dual licensed under the MIT (MIT-LICENSE.txt) or GPL (GPL-LICENSE.txt) licenses.*/.spin {--webkit-animation-name: spin;--webkit-an…

二分法:兩個有序數組長度為N,找到第N、N+1大的數

題目 兩個有序數組長度為N,找到第N、N1大的數 思路1:雙指針,O(N)復雜度 簡述思路: 如果當前A指針指向的數組A的內容小于B指針指向的數組B的內容,那么A指針往右移動,然后nums(當前已經遍歷過的數字個數)也…

Javascript -- In

http://www.caveofprogramming.com/articles/javascript-2/javascript-in-using-the-in-operator-to-iterate-through-arrays-and-objects/ http://msdn.microsoft.com/en-us/library/ie/9k25hbz2(vvs.94).aspx轉載于:https://www.cnblogs.com/daishuguang/p/3392310.html

三、自動終止訓練

有時候,當模型損失函數值預期的效果時,就可以結束訓練了,一方面節約時間,另一方面防止過擬合 此時,設置損失函數值小于0.4,訓練停止 from tensorflow import keras import tensorflow as tf import matplo…

矩陣形狀| 使用Python的線性代數

Prerequisite: Linear Algebra | Defining a Matrix 先決條件: 線性代數| 定義矩陣 In the python code, we will add two Matrices. We can add two Matrices only and only if both the matrices have the same dimensions. Therefore, knowing the dimensions o…

[數據庫]oracle客戶端連服務器錯誤

昨天晚上和今天上午用11g客戶端連同事10g服務器,報錯: The Network Adapter could not establish the connection 檢查嘗試了好多次都沒好。 用程序連,依舊是報這個錯,所以一查就解決了! 參考:http://apps…

ASP.NET 抓取網頁內容

(轉)ASP.NET 抓取網頁內容 ASP.NET 抓取網頁內容-文字 ASP.NET 中抓取網頁內容是非常方便的,而其中更是解決了 ASP 中困擾我們的編碼問題。 需要三個類:WebRequest、WebResponse、StreamReader。 WebRequest、WebRespo…

leetcode 53. 最大子序和 動態規劃解法、貪心法以及二分法

題目 給定一個整數數組 nums ,找到一個具有最大和的連續子數組(子數組最少包含一個元素),返回其最大和。 示例: 輸入: [-2,1,-3,4,-1,2,1,-5,4] 輸出: 6 解釋: 連續子數組 [4,-1,2,1] 的和最大,為 6。 進階: 如果你…

四、卷積神經網絡(Convolution Neural Networks)

一、CNN(Convolution Neural Networks) 卷積神經網絡基本思想:識別物體的特征,來進行判斷物體 卷積Convolution:過濾器filter中的數值與圖片像素值對應相乘再相加,6 * 6卷積一次(步數為1)變成4 * 4 Max Pooling:對卷積…

POJ3096Surprising Strings(map)

題意:輸入很多字符串,以星號結束。判斷每個字符串是不是“Surprising Strings”,判斷方法是:以“ZGBG”為例,“0-pairs”是ZG,GB,BG,這三個子串不相同,所以是“0-unique”…

vs助手使用期過 編譯CEGUI的問題:error C2061: 語法錯誤: 標識符“__RPC__out_xcount_part” VS2010...

第一個問題,下一個破解版的VX_A.dll,將其覆蓋以前的dll即可, 但是目錄有所要求,如下: XP系統:系統盤\Documents and Settings\用戶名\Local Settings\Application win7或者vistaData\Microsoft\VisualStud…