I am trying to search the list of trees for a given state in a file using Scala.

Here is the sample file(tab separated):-

```
Quercus acerifolia  mapleleaf oak   MN
Quercus _acutidens      CA
Quercus acutissima  sawtooth oak    AL,GA,LA,MD,MS,NC,PA,VA
Quercus agrifolia   California live oak CA
Quercus alba    white oak    AL,AR,CT,DC,DE,FL,GA,IA,IL,IN,KS,KY,LA
Quercus ajdfensis   Ajo Mountain scrub oak ,MN

```

My Code:-

```
//declaring package
package HW10

//declaring object
object TreesStub {

//importing Source package for files import
  import scala.io.Source

  //assigning the file path to filename variable
  val fileName = "trees.tsv"

  //defining Main function
  def main(args: Array[String]): Unit = {

    //reading source file from a file which is tabe separated
    val treeList: List[String] = Source.fromFile(fileName).getLines.toList

    //calling searchTrees method for a given State
    searchTrees("MN", treeList)

    //searchTrees method logic for a given State and print it
    def searchTrees(state: String, trees: List[String]): Unit = {

      //defining mutable empty map collection as "states"
      var states = collection.mutable.Map[String, String]()

      //Searching the tree list for a given state and adding the map and //tree list to the states map collection

    trees.map(x => (x.split("\t", -1))).filter((_.length > 2)).map(x =>

        //using try catch block for handling match not found exception
        try {
        if (x(2).contains(state)) states += (state -> x(0))
      }
      catch {
        //exception if caught to None
        case e: Exception => println(s"None")
      })
      //printing map "states" values
      states.foreach(println)
    }
  }
}

```

The output i am getting as :- `(MN,Quercus acerifolia)`

Expected output:-(statename, tree list)

```
(MN,Quercus acerifolia)
(MN,Quercus ajdfensis)   

```

I am able to print only one match not able to print all the matches. Not sure what is wrong in the code? Looks like the map is iterating only once not for all the matches. Please let me know how to print for all the matches?