首页 > 编程语言 > 详细

遍历数组提取List[Int]

时间:2017-09-24 20:15:55      阅读:447      评论:0      收藏:0      [点我收藏+]
 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]

原文:http://www.cnblogs.com/sayhihi/p/7588213.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!