A simple case is checking the contents of a substring (as indicated by rarry answer), e.g.
keys.exists(a.contains(_))
You did not say if you really want to find whole words. Since the rarry answer suggested that you did not do this, here is an alternative that suggests that you do this.
val a = "some random test message" val words = a.split(" ") val keys = Set("hi","random","test")
Keep in mind that a key list is only effective for small lists. With a list, the contains method usually scans the entire list linearly until it finds a match or reaches the end.
For more elements, a set is not only preferable, but also a more true representation of information. Sets are typically optimized using hash codes, etc., and therefore they need less linear searching - or nothing at all.
Rick-777 Apr 17 '13 at 18:29 2013-04-17 18:29
source share