tomap 和tolist

cala> lst0.grouped(4)
res228: Iterator[List[Int]] = non-empty iterator


scala> res228.toList
res229: List[List[Int]] = List(List(1, 2, 3, 4), List(5, 6))


scala> lst0.grouped(2)
res230: Iterator[List[Int]] = non-empty iterator


scala> res230.toList
res231: List[List[Int]] = List(List(1, 2), List(3, 4), List(5, 6))


scala> res231.flatten
res232: List[Int] = List(1, 2, 3, 4, 5, 6)


scala> res231.toMap
<console>:35: error: Cannot prove that List[Int] <:< (T, U).
              res231.toMap
                     ^


scala> res231.flatMap(x=>x.toMap)
<console>:35: error: Cannot prove that Int <:< (T, U).
              res231.flatMap(x=>x.toMap)
                                  ^


scala> res231.flatMap(x=>(x(0),x(1)))
<console>:35: error: type mismatch;
 found   : (Int, Int)
 required: scala.collection.GenTraversableOnce[?]
              res231.flatMap(x=>(x(0),x(1)))
                                ^


scala> res231.map(x=>(x(0),x(1)))
res236: List[(Int, Int)] = List((1,2), (3,4), (5,6))


scala> res236.map(x=>x.toMap)
<console>:37: error: value toMap is not a member of (Int, Int)
              res236.map(x=>x.toMap)
                              ^


scala> res231.flatMap(x=>(x(0),x(1)))
<console>:35: error: type mismatch;
 found   : (Int, Int)
 required: scala.collection.GenTraversableOnce[?]
              res231.flatMap(x=>(x(0),x(1)))
                                ^


scala> res231.map(x=>(x(0),x(1)))
res239: List[(Int, Int)] = List((1,2), (3,4), (5,6))


scala> res239.groupBy()
<console>:37: error: not enough arguments for method groupBy: (f: ((Int, Int)) => K)scala.collection.immutable.Map[K,List[(Int, Int)]].
Unspecified value parameter f.
              res239.groupBy()
                            ^


scala> res239.groupBy(_.1)
<console>:1: error: ')' expected but double literal found.
       res239.groupBy(_.1)
                       ^


scala> res239.groupBy(_._1)
res241: scala.collection.immutable.Map[Int,List[(Int, Int)]] = Map(5 -> List((5,6)), 1 -> List((1,2)), 3 -> List((3,4)))


scala> res239.groupBy(_._1).toMap
res242: scala.collection.immutable.Map[Int,List[(Int, Int)]] = Map(5 -> List((5,6)), 1 -> List((1,2)), 3 -> List((3,4)))


scala> res239.groupBy(_._1).toList
res243: List[(Int, List[(Int, Int)])] = List((5,List((5,6))), (1,List((1,2))), (3,List((3,4))))


scala> res243.toMap
res244: scala.collection.immutable.Map[Int,List[(Int, Int)]] = Map(5 -> List((5,6)), 1 -> List((1,2)), 3 -> List((3,4)))




scala> res239.toMap
res245: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2, 3 -> 4, 5 -> 6)


scala> res239
res246: List[(Int, Int)] = List((1,2), (3,4), (5,6))


scala> res245.toMap
res247: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2, 3 -> 4, 5 -> 6)


scala> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值