jeudi 17 mars 2016

Get random element from list base on condition

So i have a list with simple object:

val name:String
val value:String

val list:List[MyData]

I want to select random element with value that is not "0" or "":

val item = list.find(x => x.value != "" && x.value != "0")

But it always return the same one which is the first one




Aucun commentaire:

Enregistrer un commentaire