Hi.
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.
Hi.
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.
(= "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.
Equality in Clojure (the = function) always tests value, not identity, so two strings are = if they have the same contents.
If you want to test identity, use the identical? function.