2016-09-06 58 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' –

回答

相關問題