scala集合中加入集合_Scala中的集合

Scala提供丰富的集合库,包括可变与不可变集合。可变集合支持元素的更新、添加和删除,而不可变集合在操作时会创建新的集合。常见集合包括列表(List,使用链接列表存储,不可变)、元组(Tuple,固定数量不同类型的元素,不可变)、集(Set,不包含重复元素,可变与不可变)和映射(Map,键值对,可变与不可变)。
摘要由CSDN通过智能技术生成

scala集合中加入集合

Scala集合 (Scala collections)

A collection in programming is a simple object used to collect data. It groups together elements into a single entity (object). You can do the operation is to add, delete, update data using collections.

编程中的集合是用于收集数据的简单对象。 它将元素组合在一起成为单个实体(对象)。 您可以做的操作是使用集合添加,删除,更新数据。

In Scala, there is a huge base of collection libraries. There is a wide hierarchy of collections in Scala. Basic collections contain linear sets.

在Scala中,有大量的收藏库Scala中有广泛的集合层次结构 。 基本集合包含线性集。

The collection in Scala can be mutable as well as immutable.

Scala中集合既可变又可变。

A mutable collection is a collection whose elements can be updated and elements are added or removed from it. It allows all these operations.

可变集合是一个集合,其元素可以更新,并且可以从中添加或删除元素。 它允许所有这些操作。

An immutable collection does not allow the user to do the update operation or add and remove operation on it. There is an option to do this, but on every operation, a new collection is created with updated value and the old one is discarded.

不可变集合不允许用户执行更新操作或对其进行添加和删除操作。 可以选择执行此操作,但是在每次操作中,都会创建一个具有更新值的新集合,而旧集合将被丢弃。

Based on how they have used the collections are classified as lazy or strict. If created as a lazy collection, it may not consume memory space until they are called by the program.

根据他们的使用方式,这些收藏被分类为“懒惰”或“严格”。 如果创建为惰性集合,它可能不会消耗内存空间,直到程序调用它们为止。

As the hierarchy is concerned, we have a list of collections, with Traversable trait, it allows you to traverse the collection i.e. visit each element in the collection one by one. Traversable has followed another trait Iterable that allows iterating over the elements of the collection.

就层次结构而言,我们有一个具有Traversable特性的集合列表,它使您可以遍历集合,即逐一访问集合中的每个元素。 Traversable遵循了另一个特性Iterable ,该特性允许迭代集合的元素。

Here we are listing some commonly used collections that you will encounter in your Scala programming life. There is a huge base that supports them, this is just an overview;

在这里,我们列出了一些在Scala编程生活中会遇到的常用集合。 有一个庞大的基础支持他们,这仅仅是一个概述;

Scala List

Scala列表

The list is a linear array-like collection. It stores a similar type of elements and uses a linked list type storage method. List is an immutable collection that extends linearSeq trait.

该列表是一个类似线性数组的集合。 它存储相似类型的元素,并使用链接列表类型存储方法。 List是扩展linearSeq特性的不可变集合。

Scala Tuple

Scala元组

Tuple in Scala is an immutable collection. It can contain a fixed number of elements of different types i.e. it can hold an integer and string together.

Scala中的Tuple是一个不变的集合。 它可以包含固定数量的不同类型的元素,即可以将整数和字符串组合在一起。

Scala Set

Scala集

A set is a type collection that contains elements of the same data type, it does not contain any duplicate elements. Set can mutable as well as immutable in Scala.

集合是一个类型集合,其中包含相同数据类型的元素,但不包含任何重复的元素。 Set在Scala中既可变又可变。

Scala Map

Scala地图

A map is a collection that contains key-value pairs. To retrieve the value the key is used.

映射是包含键值对的集合。 要检索该值,请使用键。

翻译自: https://www.includehelp.com/scala/collections-in-scala.aspx

scala集合中加入集合

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值