日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

scala元组 数组_Scala中的数组

發布時間:2025/3/11 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 scala元组 数组_Scala中的数组 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

scala元組 數組

Scala中的數組 (Arrays in Scala)

An array is a linear data structure with a fixed number of elements. It is a collection that stores a fixed number Arrays in Scalf elements of the same datatype. In Scala, an array is 0 indexed, i.e. the first element has an index of zero. The last element of the array has an index of the last element minus one.

數組是具有固定數量元素的線性數據結構 。 它是一個集合,該集合在相同數據類型的Scalf元素中存儲固定數量的Array。 在Scala中, 數組的索引為0,即第一個元素的索引為零。 數組的最后一個元素的索引為最后一個元素減一。

The syntax of scala array creation is just the same as in Java but is a lot more powerful in term of features and methods backing it. It can also support sequence functions in Scala. In Scala, for defining array there is liberty on the data type. i.e. you can skip assigning of the datatype of the array. Also, it supports all types of elements.

Scala數組創建的語法與 Java中的語法相同,但是在支持它的功能和方法方面要強大得多。 它還可以在Scala中支持序列功能。 在Scala中,用于定義數組的數據類型具有自由性。 即,您可以跳過數組數據類型的分配。 此外,它支持所有類型的元素。

An array can extend up to as many dimensions as you want but only 1-D, 2-D, and 3-D arrays are commonly used. Here, we will discuss only a one-dimensional array.

數組可以擴展到任意數量的維,但是通常僅使用1-D , 2-D和3-D數組 。 在這里,我們將只討論一維數組 。

一維數組 (ONE DIMENSIONAL ARRAY)

A one-dimensional array is one which has only one row that stores data in it. It uses contagious memory allocation for elements at index 0 to total minus one.

一維數組是只有一行存儲數據的數組 。 它使用傳染性內存分配將索引0的元素總計減為1。

Syntax:

句法:

// its only single dimension...var arrayname = new Array[datatype](size)

Methods to create an array in Scala

在Scala中創建數組的方法

You can optionally specify the data type of the array in Scala.

您可以選擇在Scala中指定數組的數據類型。

// It this we have specified that the array will contain string explicitly. val name: String = new Array("Ram", "Akash", "Palak", "Geeta", "Sudhir"); //In this creation method the will itself make //the array of double datatype.val percentage = new Array(46.4 , 87.4 , 76.2 , 56.9 , 89.87)

Example:

例:

object MyClass {def add(x:Int, y:Int) = x + y;def main(args: Array[String]) {var i=0var name = Array("Ram", "Akash", "Palak", "Geeta", "Sudhir")var percentage = Array (46.4 , 87.4 , 76.2 , 56.9 , 89.87)println("Printing student names");for(i <- 0 to name.length-1){println("Student " + name(i) + " has scored " + percentage(i) + "%")}}}

Output

輸出量

Printing student names Student Ram has scored 46.4% Student Akash has scored 87.4% Student Palak has scored 76.2% Student Geeta has scored 56.9% Student Sudhir has scored 89.87%

翻譯自: https://www.includehelp.com/scala/arrays-in-scala.aspx

scala元組 數組

總結

以上是生活随笔為你收集整理的scala元组 数组_Scala中的数组的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。