How do I find the index of an element in a Scala list.
val ls = List(\"Mary\", \"had\", \"a\", \"little\", \"lamb\")
I need to get 3 if I ask f
If you want to search by a predicate, use .indexWhere(f):
.indexWhere(f)
val ls = List("Mary", "had", "a", "little", "lamb","a") ls.indexWhere(_.startsWith("l"))
This returns 3, since "little" is the first word beginning with letter l.