2016-06-19 4 views
-2

Ich habe die folgende Liste:Splitting eine Liste in mehrere Listen

List("Chapter 1", "2", "This is a sentence", "English") 

ich möchte es wie folgt aufgeteilt:

List("Chapter 1", "2", "This", "English") 
List("Chapter 1", "2", "is", "English") 
List("Chapter 1", "2", "a", "English") 
List("Chapter 1", "2", "sentence", "English") 

Antwort

2
val list = List("Chapter 1", "2", "This is a sentence", "English") 
list(2).split(" ").map(x => list.patch(2, List(x), 1)) 
+0

Seien Sie vorsichtig, da 'List # apply', dh 'Liste (2) === Liste # gilt (2)', ist keine Gesamtfunktion. 'scala> List(). apply (2) -> java.lang.IndexOutOfBoundsException: 2' –

+0

Kevin, kannst du bitte näher ausführen? –