如何得到如下结果?
val original=List("a","ab","abc","abcd","zadad","ji","jijdf","bcab", "frab","abkcdef","opabcd")
val find="ab"
val result="abc","abcd","bcab","frab","abcdef","opabcd"
答案 0 :(得分:3)
original.filter(_.contains(find))
应该做的伎俩。 filter允许您应用谓词,因此从元素类型到布尔值
的函数答案 1 :(得分:0)
您可以使用filter
检查原始列表的哪些元素包含find元素:
original.filter(_.contains(find))
编辑:
跳过等于的元素:
original.filter(elem => elem.contains(find) && !elem.equals(find) )
结果:
List[String] = List(abc, abcd, bcab, frab, abkcdef, opabcd)