Scala 知識彙總(knowledge Pooling)
阿新 • • 發佈:2020-12-14
技術標籤:技術雜壇
1、++ 該方法用於連線兩個集合
var mapList = Map.empty[String, Long]
mapList += "zho1" -> 1L
mapList += "zho2" -> 2L
mapList += "zho3" -> 3L
return => Map(zho1 -> 1, zho2 -> 2, zho3 -> 3)
val ee1 = l.map(line => {
mapList
} ).toList
println(ee1)
return => List(Map(zho1 -> 1, zho2 -> 2, zho3 -> 3), Map(zho1 -> 1, zho2 -> 2, zho3 -> 3))
val l = Array[String]("1", "2")
val ee: Map[String, Long] = l.map(line => {
mapList += line -> 5L
mapList
}).reduce( (A, B) => A ++ B)
println(ee)
return => Map(zho1 -> 1, zho2 -> 2, zho3 -> 3)
2、JSON 資料異常捕獲
物件
if (StringUtils.isNotBlank(line) && line.trim.startsWith("{") && line.trim.endsWith("}"))
集合
if(jsonObject.get("pois")!=null && jsonObject.get("pois").toString().startsWith("[") && !"null".equals(fromObject.get("records").toString()));