赞
踩
可变map,需导入import scala.collection.mutable.Map
//有初始值 val map = Map("zhangsan"->30, "lisi"->40) map("zhangsan") += 20 for((x,y) <- map) println(s"$x $y") //无初始值 val map:Map[String,Int] = Map() map += ("zhangsan"->20) map("zhangsan") += 20 for((x,y) <- map) println(s"$x $y") //可变map示例 val map:Map[String,Int] = Map() map += ("zhangsan"->20) map += ("lishi"->20) map("zhangsan") += 20 for((x,y) <- map) println(s"$x $y") for((x,y) <- map) { println(x) println(y) } if( map.contains( "lishi" )){ println("lishi 键存在,对应的值为 :" + map("lishi")) }else{ println("lishi 键不存在") }
不可变map形式与可变map相同,不导包就行。
导包xml:
<dependency>
<groupId>com.huaban</groupId>
<artifactId>jieba-analysis</artifactId>
<version>1.0.2</version>
</dependency>
应用:
import com.huaban.analysis.jieba.JiebaSegmenter
var str = new JiebaSegmenter().sentenceProcess(curtitle).toArray() //调用jieba分词
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。