运行环境:Jdk1.7、scala-2.10.4
package study
/**
* Document:本类作用---->拆分List
* User: yangjf
* Date: 2016/8/14 8:57
*/
object TestArrays {
def main(args: Array[String]) {
val lists=List(12,34,5,19,56,23,16)
val end: (List[Int], List[Int]) =lists.partition(_>20)
println("获得新元祖:"+end)
val maps=Map(1->"tom",2->"jim",3->"cassie",4->"hello",5->"worldss")
val ends1: (Map[Int, String], Map[Int, String]) =maps.partition(_._2.length>3)
println("获取新元祖:"+ends1)
val sets=Set(23,12,45,21,56,62,55,23)
val setends=sets.partition(_>40)
println("获取新元祖:"+setends)
}
}
结果:
获得新元祖:(List(34, 56, 23),List(12, 5, 19, 16))标签:Map,val,scala,--,23,List,Int,元祖 From: https://blog.51cto.com/u_13966077/5819864
获取新元祖:(Map(5 -> worldss, 3 -> cassie, 4 -> hello),Map(1 -> tom, 2 -> jim))
获取新元祖:(Set(56, 45, 55, 62),Set(21, 12, 23))