Question: question 1:

```
val a: List[String] = List("0","aa","1","2","3","aa","4","5","6","7")

```

how to get the next two elements after the "aa" element then put these elements into each independent List:

expect:

```
List(List("1","2"),List("4","5"))

```

question 2:

```
val b: List[String] = List("0","aa","1","2","3","#","aa","4","5","#","6","7")

```

how to get the elements between "aa" and "#" (exclude "aa" and "#") then put these elements into each independent List:

expect:

```
List(List("1","2","3"),List("4","5"))

```

Answer: 
You can use `sliding` and `tails` to get an `Iterator` of relevant sublists, and then use `collect` to both filter out the `List`s you need and convert them to the required format in a single operation:

For the first question:

```
scala> val a: List[String] = List("0","aa","1","2","3","aa","4","5","6","7")
a: List[String] = List(0, aa, 1, 2, 3, aa, 4, 5, 6, 7)

scala> a.sliding(3).collect {
  case "aa" :: rest => rest
}.toList
res1: List[List[String]] = List(List(1, 2), List(4, 5))

```

Or:

```
scala> a.tails.collect {
  case "aa" :: rest => rest.take(2)
}.toList
res2: List[List[String]] = List(List(1, 2), List(4, 5))

```

For the second question:

```
scala> val b: List[String] = List("0","aa","1","2","3","#","aa","4","5","#","6","7")
b: List[String] = List(0, aa, 1, 2, 3, #, aa, 4, 5, #, 6, 7)

scala> b.tails.collect {
  case "aa" :: rest => rest.takeWhile(_ != "#")
}.toList
res3: List[List[String]] = List(List(1, 2, 3), List(4, 5))

```
For question 1, using `tails` would be fun

```
val a: List[String] = List("0","aa","1","2","3","aa","4","5","6","7")
a.tails.toList.filter(_.headOption == Some("aa")).map(_.drop(1).take(2)) 

>> List[Seq[String]] = List(List("1", "2"), List("4", "5"))

```