How to check the equality of strings in clojure without invoking java.lang.String?

前端 未结 2 1010
情歌与酒
情歌与酒 2021-02-03 19:47

Is there any way in clojure to check the equality of strings? i.e. I need to know, whether their contents is equal, not location.

thanks.

2条回答
  •  自闭症患者
    2021-02-03 20:18

    (= "hello" (str "hel" "lo"))
    ; => true 
    

    The JVM has a string pool that holds at most one entry per value, so identity and value equality are the same comparison. There are ways using StringBuilder. and String. where this is not strictly true, but because the clojure equality function calls .equals, a value comparison will be performed if the identities are different.

提交回复
热议问题