Scala day4(tuple, set and map)

Foreword

Hi!! my dear friends, are you lazy at today?? Oh! I am also lazy sometimes, but you will know keep study that’s a right way at last. Now!! let’s start new travel about Scala.

Text

The all Codes in file day3.scala, like the below program:

import scala.collection.mutable
import scala.collection.immutable.HashSetobject day3 {def main(args:Array[String]): Unit = {System.out.println("Scala is make me happy!!");Tuple_operation();}def Tuple_operation(): Unit = {
//    val empty_tup = ();
//    System.out.println(empty_tup);val pair = (81,"number","Y");System.out.println(pair);
//    pair(0) = 5;System.out.println(pair(0));System.out.println(pair(2));System.out.println(pair(1));
//    System.out.println(pair[1]);System.out.println(pair._1);System.out.println(pair._2);System.out.println(pair._3);var capital = Set("Beijing","Tokyo","London");capital += "Paris";System.out.println(capital);System.out.println(capital.contains("Washington"));val exam = Set("123","456");System.out.println(exam);val Musicset = mutable.Set("One day","Lemon Tree");Musicset += "Tomorrow will be better";System.out.println(Musicset);Musicset.+=("Waiting for love");System.out.println(Musicset);Musicset.+=("MoonLight");System.out.println(Musicset);Musicset += "Oblivion";System.out.println(Musicset);var video = mutable.Set("KaSha","Hero");System.out.println(video);
//    Musicset = video;var Name = HashSet("Tom","Sam");System.out.println("HashSet:");Name += "Amy";System.out.println(Name);Name += "Pan"System.out.println(Name);val letters = HashSet("ABC","DEF","RTF");System.out.println(letters);val MAP = mutable.Map[String,String]();MAP += ("music" -> "后來");MAP += ("movie" -> "第一滴血")MAP += ("game" -> "war3");System.out.println(MAP);System.out.println(MAP("game"));System.out.println(MAP("music"));System.out.println(MAP("movie"));val Mapper = Map(1 -> "A",2 -> "B",3 -> "C");System.out.println(Mapper);System.out.println(Mapper(1));System.out.println(Mapper(2));System.out.println(Mapper(3));}
}

The first example, it’s about the tuple defined and get the tuple values. It like the below Codes:

	val pair = (81,"number","Y");System.out.println(pair);System.out.println(pair(0));System.out.println(pair(2));System.out.println(pair(1));System.out.println(pair._1);System.out.println(pair._2);System.out.println(pair._3);

Output Result:
請添加圖片描述
From the above Codes, we know the process of tuple type defined. Through subscript couldn’t gain value at the previous relase. In 3.6.4 relase, the reason is like the below pictures:
請添加圖片描述
請添加圖片描述
It’s use apply() function, it’s like List type, so it could use subscript to gain the tuple value.

Next, the example is set type declared, codes like the below program:

    var capital = Set("Beijing","Tokyo","London");capital += "Paris";System.out.println(capital);System.out.println(capital.contains("Washington"));val exam = Set("123","456");System.out.println(exam);

Output Result:
請添加圖片描述
From the Output Result, we know var type could let set type mutable, contains() function, it could judge data in the set. Val type couldn’t change the set element.

Then, we look the mutable set, it like the below codes:

 	val Musicset = mutable.Set("One day","Lemon Tree");Musicset += "Tomorrow will be better";System.out.println(Musicset);Musicset.+=("Waiting for love");System.out.println(Musicset);Musicset.+=("MoonLight");System.out.println(Musicset);Musicset += "Oblivion";System.out.println(Musicset);var video = mutable.Set("KaSha","Hero");System.out.println(video);
//    Musicset = video;

Output Result:
請添加圖片描述
From the above program, we know val type couldn’t limit the mutable set, the reason is mutable set is change itself, isn’t change the Musicset Object. if we uncomment, then new Object video will assign value to Musicset Object, but the val type couldn’t permit the operation and pop error. And set is disordered.

After, we watch the example about immutable set, like the below codes:

 	var Name = HashSet("Tom","Sam");System.out.println("HashSet:");Name += "Amy";System.out.println(Name);Name += "Pan"System.out.println(Name);val letters = HashSet("ABC","DEF","RTF");System.out.println(letters);

Output Result:
請添加圖片描述
From the result, we know var type could effect the immutable set, it also could add element to set.

At last, we look this codes:

	val MAP = mutable.Map[String,String]();MAP += ("music" -> "后來");MAP += ("movie" -> "第一滴血")MAP += ("game" -> "war3");System.out.println(MAP);System.out.println(MAP("game"));System.out.println(MAP("music"));System.out.println(MAP("movie"));val Mapper = Map(1 -> "A",2 -> "B",3 -> "C");System.out.println(Mapper);System.out.println(Mapper(1));System.out.println(Mapper(2));System.out.println(Mapper(3));

Output Result:
請添加圖片描述
From the program result, we know map type has two ways to create it. One is obviously point itself all types and haven’t put datas, anthor is directly put datas, it could identify these datas corresponding itselves types.

In the end

I gratitude for your watch my articles, if you still learn the Scala, you are excellent, I admire you, I hope you could point some mistakes in my passages. The reason is I’m not a smart man. Please you remember: anything, you must insist do it at last that you will become winner in this game. Your Pan.【One human low-quality male】

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

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

相關文章

docker compose搭建博客wordpress

一、前言 docker安裝等入門知識見我之前的這篇文章 https://blog.csdn.net/m0_73118788/article/details/146986119?fromshareblogdetail&sharetypeblogdetail&sharerId146986119&sharereferPC&sharesourcem0_73118788&sharefromfrom_link 1.1 docker co…

第二期:[特殊字符] 深入理解MyBatis[特殊字符]MyBatis基礎CRUD操作詳解[特殊字符]

前言 🌟 在掌握了 MyBatis 的基本配置與環境搭建之后,接下來的重點便是深入理解其核心功能——CRUD 操作(增刪改查)。💻 數據庫操作是任何應用開發中不可或缺的一環,而 MyBatis 正是通過靈活的 SQL 映射機…

Java面試黃金寶典46

1. Python 如何寫爬蟲 定義:Python 爬蟲是借助 Python 語言編寫程序,模擬瀏覽器行為向目標網站發送 HTTP 請求,獲取網頁內容,再通過解析工具提取所需數據的程序。其本質是自動化的數據采集過程。要點: 發送請求:利用requests庫發送 HTTP 請求,如 GET、POST 等,獲取網頁…

建設“大數據智慧招商平臺”,助力園區突破招商瓶頸!

在數字經濟高速發展的今天,傳統招商模式正面臨信息不對稱、效率低下、匹配不精準等瓶頸。產業園區作為區域經濟發展的核心載體,亟需借助智能化手段提升招商效能。構建大數據智慧招商平臺,利用大數據、人工智能等技術獲取精準招商線索、促進產…

Vue事件修飾符課堂練習

Vue事件修飾符課堂練習 題目?:基于 Vue 2.0,使用事件修飾符 .stop、.prevent、.capture、.self 和 .once,為按鈕綁定 click 事件,并展示每個修飾符的作用。 要求?: 創建一個 Vue 實例,并綁定到一個 HT…

【C#】線程回調

在 C# 中,線程回調是一種常見的編程模式,用于在線程完成任務后執行某些操作。通過使用 Thread 類或其他更高層次的并發工具(如 Task),可以實現線程回調的功能。 回調機制 特點 直接性:回調通常是通過委托…

【C++游戲引擎開發】第14篇:視圖空間與相機坐標系

一、視圖空間的基礎數學框架 1.1 齊次坐標與變換矩陣 三維坐標系變換采用44齊次坐標矩陣,其通用形式為: M = [ A 3 3 b 3 1 0 1 3 1 ] \mathbf{M} = \begin{bmatrix} \mathbf{A}_{33} & \mathbf{b}_{31} \\ \mathbf{0}_{13} & 1 \end{bmatrix} M=[A33?013??…

【大模型理論篇】關于生成式模型中聯合分布概率學習必要性以及GPT是生成式模型的討論

1. 背景 之前我們在《生成式模型與判別式模型對比(涉及VAE、CRF的數學原理詳述)》以及《生成式模型算法原理深入淺出(涉及Stable Diffusion、生成對抗網絡、高斯混合模型、隱馬爾可夫模型、樸素貝葉斯等算法原理分析及生成式模型解釋)》中,我…

DIP支付方式改革下各種疾病醫療費用的影響以及分析方法研究綜述

DIP支付方式改革下各種疾病醫療費用的影響以及分析方法研究綜述 摘要 本文綜述了DIP支付方式改革對不同疾病醫療費用的影響及其分析方法,通過分析12篇相關文獻,探討了DIP支付方式在控制醫療費用、優化費用結構、提升醫療服務效率等方面的作用及其局限性…

嵌入式硬件篇---單片機周期

文章目錄 前言 前言 在單片機中,時序控制是其執行指令和協調外設的核心基礎。以下是單片機中常見的各種周期及其詳細說明,以層次結構展開: 時鐘周期(Clock Cycle) 定義: 時鐘周期是單片機的最小時間單位&a…

游戲引擎學習第221天:(實現多層次過場動畫)

資產: intro_art.hha 已發布 在下載頁面,你會看到一個新的藝術包。你將需要這個藝術包來進行接下來的開發工作。這個藝術包是由一位藝術家精心制作并打包成我們設計的格式,旨在將這些藝術資源直接應用到游戲中。它包含了許多我們會在接下來的直播中使用…

【3GPP核心網】【5G】精講5G系統的策略和計費控制框架

1. 歡迎大家訂閱和關注,精講3GPP通信協議(2G/3G/4G/5G/IMS)知識點,專欄會持續更新中.....敬請期待! 目錄 1. 系統架構 1.1 非漫游架構 1.2 漫游架構 1.3 支持Rx接口 2. 服務化接口及參考點 2.1 PCF 與 AF 間接口 2.2 PCF與SMF間接口 2.3 PCF與AMF間接口 2.4 V-PC…

榕壹云門店管理系統:基于Spring Boot+Mysql+UniApp的智慧解決方案

項目背景:數字化賦能服務行業,破解傳統門店管理痛點 在消費升級與數字化轉型浪潮下,傳統服務行業(如美容、美發、美甲、采耳等)面臨諸多管理挑戰:會員流失率高、預約排班混亂、員工績效統計低效、數據孤島等…

開發效率提升200%——cursor

cursor帶來的編程"革命" 高級語言編程轉為"自然語言編程"借助cursor,直接超越初級后臺開發、超越初級前端開發、超越初級測試、超越初級UI,產研一體linux命令只用學不用記,語言描述就是命令給一個表結構流程提示詞&…

UE4 踩坑記錄

1、Using git status to determine working set for adaptive non-unity build 我刪除了一個沒用的資源,結果就報這個錯,原因就是這條命令導致的, 如果這個項目是git項目, ue編譯時會優先通過 git status檢查哪些文件被修改&#…

藍橋杯 2025 C++組 省 B 題解

可分解的正整數 算法&#xff1a;思維 因為可以有負數 所以除了1以外的任何數都可以構造 當這個數為x構造方法為 -(x-1) -(x-2) -(x-3) ....-1 0 1...x-3 x-2 x-1 x 除了x&#xff0c;x以前的數都會被負數抵消 #include <bits/stdc.h> #define ll long long ll a…

docker創建容器添加啟動--restart選項

一、通過 Docker 命令直接修改已啟動的容器&#xff08;推薦-已驗證&#xff09; 操作步驟&#xff1a; 1.執行更新命令&#xff1a; docker update --restartalways <容器名或ID>此命令會將容器的重啟策略調整為 always&#xff08;無論容器以何種狀態退出&#xff0…

redission鎖釋放失敗處理

redission鎖釋放失敗處理 https://www.jianshu.com/p/055ae798547a 就是可以刪除 鎖的key 這樣鎖就釋放了&#xff0c;但是 還是要結合業務&#xff0c;這種是 非正規的處理方式&#xff0c;還是要在代碼層面進行處理。

【語音識別】vLLM 部署 Whisper 語音識別模型指南

目錄 1. 模型下載 2. 環境安裝 3. 部署腳本 4. 服務測試 語音識別技術在現代人工智能應用中扮演著重要角色&#xff0c;OpenAI開源的Whisper模型以其出色的識別準確率和多語言支持能力成為當前最先進的語音識別解決方案之一。本文將詳細介紹如何使用vLLM&#xff08;一個高…

Windows Server 2019 安裝 Docker 完整指南

博主本人使用的是離線安裝 1. 安裝前準備 系統要求 操作系統&#xff1a;Windows Server 2019&#xff08;或 2016/2022&#xff09;權限&#xff1a;管理員權限的 PowerShell網絡&#xff1a;可訪問互聯網&#xff08;或離線安裝包&#xff09; 啟用容器功能 Install-Win…