zoukankan      html  css  js  c++  java
  • 列表的操作

    列表的连接::::

    列表的长度 length

    列表的头部和头部外的部分:head tail (效率高)

    列表的尾部和尾部外的部分:last init(效率低)

    反转列表:reverse

    drop take splitAt

    apply indices

    toString mkString

    列表转换:toArray copyToArray

    列表映射:map flatMap foreach

    列表过滤:filter partition find takeWhile dorpWhile span

    列表论断:forall exists

    列表的折叠 :(0 /: list)(_+_) list :(_+_)

    package exp {
        object Main {
    
            def main(args: Array[String]): Unit = {
                val x = List.concat(Array(1,2,3),Array(4,5,6),Set(7,8,9));    
                println((List[Int]() /: x){(p,q)=>q::p}); //左折叠操作函数的第一个类型是初始参数类型
                // -> List(9, 8, 7, 6, 5, 4, 3, 2, 1)
                println((x : List[Int]())((p,q)=>p::q)); //右折叠操作函数的第一个类型是列表元素类型
                // -> List(1, 2, 3, 4, 5, 6, 7, 8, 9)
            }
        }
    }
    

      

  • 相关阅读:
    2.7 矩阵的秩
    HDU
    HDU
    HDU
    HDU
    HDU
    hdu 5179 beautiful number(数位dp)
    ACdream
    CodeForces
    <a>标签中 href="/" 和 hideFocus="true"
  • 原文地址:https://www.cnblogs.com/scala/p/3645119.html
Copyright © 2011-2022 走看看