2016-09-06 53 views
0

我这样做,对空值的过滤列表:有没有更好的方法在列表中过滤null?

val myList: List<Any?> = [...] 
myList.filter { it != null }.map { it!! } 
myList.get(0).xxx // don't need to write "?." 

如果我不添加map,列表不会成为List<...>。有没有更好的方法来做到这一点?

+1

你可以用'mylist.filterNotNull()[0] .xxx' –

回答

相关问题