How to filter a Seq in Scala -


i have question, have scala seq of fruit objects, name member variable of object name of fruit

fruits: seq[fruit] = list(banana, apple, jackfruit, pineapple, grapes, watermelon, papaya, orange, pomegranate, strawberry) 

and have scala string contains name of fruit separated comma like

val ilike = "apple, grapes, watermelon, guava" 

i need filter above seq such contain objects of fruit like, result should be,

fruits: seq[fruit] = list(apple, grapes, watermelon) 

i tried java way, interested how work same in scala way. googled bit couldn't find correct answer.

thank in advance.

an more succinct way - use intersect

scala> val = ilike.split(", ") like: array[string] = array(pineapple, grapes, watermelon, guava)  scala> fruits.intersect(like) res1: seq[string] = list(pineapple, grapes, watermelon) 

Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

php - Improving script execution time -

How to provide Authorization & Authentication using Asp.net, C#? -