我想比較兩個字符串在斯卡拉。以下是功能。在斯卡拉比較字符串 - 等於==
def max(x:Int, y:String): String = {
| if (y=="Happy") "This is comparing strings as well"
| else "This is not so fair"
| if (x > 1) "This is greater than 1"
| else "This is not greater than 1"
| }
從some answers我認爲我可以用「==」符號來比較字符串。我給出了以下輸入並獲得了以下輸出。我錯過了什麼或斯卡拉表現不同?
max (1,"Happy")
res7: String = This is not greater than 1
println(max(2, "sam"))
This is greater than 1
我覺得這個問題是不是與''==但事實上,你有兩個if/else.https://stackoverflow.com/a/12560532/3072566 – litelite
謝謝@litelite。我會保留這個問題供其他人蔘考。 – Dinesh
@Dinesh,請接受答案。 –