List的一阶函数操作代码实战详解之Scala学习笔记-24

package com.leegh.dataset

/**
* @author Guohui Li
*/
object List_FirstOrder_Ops {

def main(args: Array[String]): Unit = {
println(List(1, 2, 3, 4) ::: List(4, 5, 6, 7, 8) ::: List(10, 11))
println(List(1, 2, 3, 4) ::: (List(4, 5, 6, 7, 8) ::: List(10, 11)))
println(List(1, 2, 3, 4).length)

val bigData = List("Hadoop", "Spark", "Kaffka")
println(bigData.last)
println(bigData.init) //除了最后一个元素的其他元素
println(bigData.reverse)
println(bigData)
println(bigData take 2) //取前两个元素
println(bigData drop 2) //去除前两个元素
println(bigData splitAt 2) //把集合列表分为两部分
println(bigData apply 2)
println(bigData(2))

val data = List(‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘)
println(data.indices) //索引
println(data.indices zip data) //zip 拉链操作,配对
println(data.zipWithIndex)
println(data.toString)
println(data.mkString("[", ",", "]"))
println(data.mkString(" "))
println(data.mkString)

val buffer = new StringBuilder
data addString (buffer, "(", ";;", ")")
println(buffer)

val array = data.toArray
println(array.toList)

val new_Array = new Array[Char](10)
data.copyToArray(new_Array, 3)
new_Array.foreach(print)
println

val iterator = data.toIterator
println(iterator.next)
println(iterator.next)
}

}

附:

本博客说明:

1.整理思路,提高自己。

2.受教于王家林老师,?有所收获,故推荐。

3.博客注重实践,多余的文字就不多说了,都是做技术的。

4.信息来源于 DT大数据梦工厂微信公众账号:DT_Spark。?

DT大数据梦工厂的微信公众号是DT_Spark,每天都会有大数据实战视频发布,请您持续学习。

Scala 深入浅出实战经典(1-64讲)完整视频、PPT、代码下载:

百度云盘:http://pan.baidu.com/s/1c0noOt6
腾讯微云:http://url.cn/TnGbdC
360云盘:http://yunpan.cn/cQ4c2UALDjSKy 访问密码 45e2

时间: 2024-12-29 01:57:00

List的一阶函数操作代码实战详解之Scala学习笔记-24的相关文章

第33讲:List的一阶函数操作代码实战详解

操作的参数不是函数,就是一阶函数 我们通过具体的代码来说明: package com.dt.scala.dataset object ListFirstOrderOps {   def main(args: Array[String]): Unit = {     //列表合并,使用:::操作符     println(List(1,2):::List(3,4):::List(5,6))     println(List(1,2):::(List(3,4):::List(5,6)))     /

Scala中隐式对象代码实战详解之Scala学习笔记-54

package com.leegh.implicits /** * @Tuthor Guohui Li */abstract class Template[T] { def add(x: T, y: T): T} abstract class SubTemplate[T] extends Template[T] { def unit: T} object Implicits_Object { def main(args: Array[String]): Unit = { implicit obj

Scala中路径依赖代码实战详解之Scala学习笔记-42

package com.leegh.parameterization /** * @author Guohui Li */ class Outer { private val x = 10 class Inner { private val y = x + 10 }} object Path_Dependence { def main(args: Array[String]): Unit = { val outer = new Outer val inner = new outer.Inner

Scala中隐式类代码实战详解之Scala学习笔记-53

package com.leegh.implicits import java.io.Fileimport scala.io.Source /** * @author Guohui Li */object Context_Helper { implicit class FileEnhance(file: File) { def read = Source.fromFile(file.getPath).mkString } implicit class Op(x: Int) { def add(s

Scala中复合类型实战详解之Scala学习笔记-44

package com.leegh.parameterization import com.leegh.parameterization.Compound_Type /** * @author Guohui Li */ trait Compound_Type1;trait Compound_Type2;class Compound_Type extends Compound_Type1 with Compound_Type2object Compound_Type { def compound_

Scala中结构类型实战详解之Scala学习笔记-43

package com.leegh.parameterization /** * @author Guohui Li */ class Structural { def open() = print("A class instance Opened") } object Structural_Type { def main(args: Array[String]): Unit = { init(new { def open() = println("Opened")

Scala中Dependency Injection实战详解之Scala学习笔记-47

package com.leegh.parameterization /** * @author Guohui Li */ trait Logger { def log(msg: String) }trait Auth { auth: Logger => def act(msg: String) { log(msg) }} object DI extends Auth with Logger { override def log(msg: String) = println(msg)} obje

Scala提取器Extractor实战详解之Scala学习笔记-19

package com.leegh.pattern_match /** * @author Guohui Li */object Extractor { def main(args: Array[String]): Unit = { def match_array(arr: Any) = arr match { case Array(0) => println("Array" + "0") case Array(x, y) => println(&quo

Scala中Curring实战详解之Scala学习笔记-16

package com.leegh.function /** * @author Guohui Li */object Curring { def main(args: Array[String]): Unit = { def muliple(x: Int, y: Int) = x * y def multipleOne(x: Int) = (y: Int) => x * y println(multipleOne(6)(7)) def curring(x: Int)(y: Int) = x *