简体   繁体   中英

Transform Array[Seq[(Int, String)]] to Seq[(Int, String)] in SCALA

I'm pretty new to scala and I can't find a way to get rid of my Array[Seq[(Int, String)]] to one big Seq[(Int, String)] containing the (Int, String) of each Seq[(Int, String)].

Here is a more explicit example:

Array[Seq[(Int, String)]]:

ArrayBuffer((1,a), (1,group), (1,of))

ArrayBuffer((2,following), (2,clues))

ArrayBuffer((3,three), (3,girls))

And here is what I want my Seq[(Int, String)]] to looks like:

Seq((1,a), (1,group), (1,of), (2,following), (2,clues), (3,three), (3,girls))

You are looking for flatten : val flat: Array[(Int, String)] = originalArray.flatten

If you want it to be a Seq rather than an array (good choice), just tuck a .toSeq at the end: originalArray.flatten.toSeq

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM