scala入门初级代码训练-04MapTupleZip

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

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

There I am,in the world more exciting!

by postbird

www.ptbird.cn


04MapTupleZip


 

package com.ptbird.scala

/**
* Created by postbird on 2016/5/25.
*/
object MapTupleZip {
def main(args: Array[String]): Unit = {
/**
* Map
*/
//map长度不可变化

val map1 = Map("name" -> "ptbird", "age" -> 14)
//for((k,v) "ptbird", "age" -> 12)
val map2Value = map2.getOrElse("love", 2)
map2 += ("love" -> "ptbird")
val map2Value2 = map2.getOrElse("love", 2)
// println(map2Value)
// println(map2Value2)

val map3=scala.collection.immutable.SortedMap("name" -> "ptbird", "age" -> 12)
// println(map3)
/**
* Tuple
* 从1开始的tuple
* */
val t1=(1,2,3,4,"asd")
// println(t1._1) //1

//println("Spark".partition(_.isUpper)) //(S,park)

/**
* zip
* */
val arr1=Array("[","-","]")
val arr2=Array(1,2,3)
val p=arr1.zip(arr2)
for(i

欢迎评论。
lingkb » scala入门初级代码训练-04MapTupleZip

发表评论