1. 程式人生 > >遍歷數組提取List[Int]

遍歷數組提取List[Int]

ges spa clas blog cnblogs atm -1 tof reverse

 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]