遍历数组提取List[Int]

Posted sayhihi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了遍历数组提取List[Int]相关的知识,希望对你有一定的参考价值。

 1 def toFlatMap(input:List[Any],result:List[Int]):List[Int]=input match{
 2   case h::t=>h match {case e:Int=>toFlatMap(t,e::result)
 3                       case  x:List[Any] => toFlatMap(t,toFlatMap(x,result))
 4                       case _=>toFlatMap(t,result)}
 5   case Nil=>result
 6   case _=> result
 7 }
 8 
 9 val myList=List("a",List("a,",1000,2000),11,2,3,4,"abc",5,List(6,List(100,200),2,1).reverse,"a")10 
11 print(toFlatMap(myList,List[Int]()).reverse)

 

 

以上是关于遍历数组提取List[Int]的主要内容,如果未能解决你的问题,请参考以下文章