原创文章,转载请注明出处!

原文地址: http://www.ptbird.cn/2016/07/19/scala-chuji-demo-30/

There I am,in the world more exciting!

by postbird

www.ptbird.cn



package com.ptbird.scala /** * Created by postbird on 2016/5/26. */ object ListTest { def main(args: Array[String]): Unit = { //List内部的类型是一致的 val bigData = List("Hadoop", "Spark") val data = List(1, 2, 3) //其他的声明方式 val bigData_Core = "Hadoop" :: ("Spark" :: "Scala" :: Nil) //头元素 :: (其他元素 :: Nil) //右结合 val data_Int = 1 :: 2 :: 3 :: Nil println(data.isEmpty) println(data.head) println(data.tail.head) //除去tail元素的所有元素 // false // 1 // 2 val List(a, b) = bigData println(a + "--" + b) //Hadoop--Spark val x::y::rest=data println(x+" "+y+" "+rest) // 1 2 List(3) val shuffleData=List(1,2,4,2,6,4,48,5) println(shuffleData.sorted) //List(1, 2, 2, 4, 4, 5, 6, 48) def sortList(list:List[Int]):List[Int]=list match{ case List()=>List() case head::tail=>compute(head,sortList(tail)) } def compute(data:Int,dataSet:List[Int]):List[Int]=dataSet match{ case List()=>List(data) case head::tail=>if(data