遍历数组提取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)

 

 

posted on 2017-09-24 19:32  sayhihi  阅读(1496)  评论(0编辑  收藏  举报