8.29. Scala Collection

发布时间 :2023-11-17 23:00:02 UTC      

Scala provides a good set of collection implementations, providing some abstractions of collection types.

Scala collections are divided into mutable and immutable collections.

Mutable sets can be updated or extended where appropriate. This means that you can modify, add, and remove elements of a collection.

The immutable set class, by contrast, will never change. However, you can still simulate add, remove or update operations. But these operations will return a new collection in each case, leaving the original collection unchanged.

Next, we will introduce the applications of several common collection types:

Serial number

Set and description

1

The characteristic of Scala List (list) List is that its elements are storedin a linear manner, and duplicate objects can be stored in the collection.

Reference API document

2

Scala Set Set is the simplest kind of collection. The objects in the collection are not sorted in a specific way, and there are no duplicate objects.

Reference API document

3

Scala Map (mapping) Map is a set of mapping key objects and value objects, each element of which contains a pair of key objects and value objects.

Reference API document

4

Scala tuples are collections of different types of values

5

Scala Option Option [T] Represents a container that may or may not contain avalue.

6

An Scala Iterator is not a container, but rather a method of accessing the elements in the container one by one.

8.29.1. Example #

The following code determines that the definition examples of all the above collection types are demonstrated:

//Define an integer list
Val x=List (1,2,3,4)
//Define Set
Val x=Set (1,3,5,7)
//Define Map
Val x=Map ("one" ->1, "two" ->2, "three" ->3)
//Create tuples of two different types of elements
Val x=(10, "Runoob")
//Define Option
Val x: Option [Int]=Some (5)

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.

Powered by Django & PostgreSQL (with PostGIS)