object Map_Tuple {
def main(args: Array[String]): Unit = {
//不可变映射
val map = Map("book" -> 10, "gun" -> 18, "ipad" -> 1000)
for ((k, v) <- map) yield (k, v * 0.9)
//可变映射
val scores = scala.collection.mutable.Map("Scala" -> 7, "Hadoop" -> 8, "Spark" -> 10)
val hadoopScore = scores.getOrElse("Hadoop", 0)
scores += ("R" -> 10)
scores -= "Hadoop"
//按key的字典顺序进行排序
val sortedScore = scala.collection.mutable.SortedSet("Scala" -> 7, "Hadoop" -> 8, "Spark" -> 10)
//Tuple很常用!!!
val tuple = (1, 2, 3.14, "Rocky", "Spark")
val third = tuple._3
val (first, second, thirda, fourth, fifth) = tuple
val (f, s, _, _, _) = tuple
//partition方法返回的是一对字符串,分别包含了满足某个条件和不满足某个条件的字符
"Rocky Spark".partition(_.isUpper)
val symbols = Array("[", "-", "]")
val counts = Array(2, 5, 2)
val pairs = symbols.zip(counts)
for ((x, y) <- pairs) print(x * y)
}
}
本博客说明:
1.整理思路,提高自己。
2.受教于王家林老师,有所收获,故推荐。
3.博客注重实践,多余的文字就不多说了,都是做技术的。
4.信息来源于 DT大数据梦工厂微信公众账号:DT_Spark。
DT大数据梦工厂的微信公众号是DT_Spark,每天都会有大数据实战视频发布,请您持续学习。
Scala 深入浅出实战经典(1-68讲)完整视频、PPT、代码下载:
百度云盘:http://pan.baidu.com/s/1o6HwSPG
腾讯微云:http://url.cn/TnGbdC
360云盘:http://yunpan.cn/cQ4c2UALDjSKy 访问密码 45e2