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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

scala 空列表_如何在Scala中展平列表列表?

發布時間:2025/3/11 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 scala 空列表_如何在Scala中展平列表列表? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

scala 空列表

Flattening of List is converting a list of multiple List into a single List. To flatten List of List in Scala we will use the flatten method.

扁平化列表是將多個列表的列表轉換為單個列表。 為了在Scala中扁平化List列表,我們將使用flatten方法。

Syntax:

句法:

val newList = list.flatten

Program to flatten a list of list with numerical values

程序用數值拼合列表列表

object MyClass {def main(args: Array[String]) {val ListofList = List(List(214, 56), List(6, 12, 34, 98))println("List of List: " + ListofList)println("Flattening List of List ")val list = ListofList.flattenprintln("Flattened List: " + list)} }

Output

輸出量

List of List: List(List(214, 56), List(6, 12, 34, 98)) Flattening List of List Flattened List: List(214, 56, 6, 12, 34, 98)

The same flatten method can also be applied to convert sequence of sequence to a single sequence(Array, list, Vector, etc.).

同樣的展平方法也可以應用于將序列序列轉換為單個序列( 數組 ,列表,向量等)。

You can convert list of lists to list of type strings in two ways.

您可以通過兩種方式將列表列表轉換為類型字符串列表

Let's explore how to?

讓我們探索如何?

Program:

程序:

object MyClass {def main(args: Array[String]) {val ListofList = List(List("Include", "Help"), List("Programming", "Tutorial"))println("List of List: " + ListofList)println("Flattening List of List ")val list = ListofList.flattenprintln("Flattened List: " + list)} }

Output

輸出量

List of List: List(List(Include, Help), List(Programming, Tutorial)) Flattening List of List Flattened List: List(Include, Help, Programming, Tutorial)

Another way could split the list of list into character lists.

另一種方法可以將列表列表拆分為字符列表。

Program:

程序:

object MyClass {def main(args: Array[String]) {val ListofList = List("Include", "Help")println("List of List: " + ListofList)println("Flattening List of List ")val list = ListofList.flattenprintln("Flattened List: " + list)} }

Output

輸出量

List of List: List(Include, Help) Flattening List of List Flattened List: List(I, n, c, l, u, d, e, H, e, l, p)

翻譯自: https://www.includehelp.com/scala/how-to-flatten-a-list-of-list-in-scala.aspx

scala 空列表

總結

以上是生活随笔為你收集整理的scala 空列表_如何在Scala中展平列表列表?的全部內容,希望文章能夠幫你解決所遇到的問題。

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