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.mzph.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…