val signList1 = Set("(", "[", " VIA ")
val signList2 = Set('(', '[', " VIA ")
val returnStr2 = "xx VIA yy"
var returnStr3 = returnStr2
signList2.foreach(e => {
val pos = returnStr2.indexOf(e)
if (pos == 0) {
returnStr3 = returnStr2.substring(pos + 1).trim
}
else if (pos > 0) {
returnStr3 = returnStr2.substring(0, pos).trim
}
})
println(returnStr3)
Run Code Online (Sandbox Code Playgroud)
returnStr3应该是xx,而它被赋予xx VIA yy如果我使用signList2同时给予xx当我使用signList1.这是为什么现象呢?欣赏它.
implicit val ord:Ordering[String] = Ordering.by(_.length)
var nameQueue = new PriorityQueue[String]()
nameQueue.+=("SINES","YINE","WIRAEUS")
nameQueue.foreach(println)
Run Code Online (Sandbox Code Playgroud)
输出是:
WIRAEUS
YINE
SINES
Run Code Online (Sandbox Code Playgroud)
这看起来令人困惑.任何人都可以帮助解释订购的机制吗?