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

前端 未结 2 984
情歌与酒
情歌与酒 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 19:59

    Equality in Clojure (the = function) always tests value, not identity, so two strings are = if they have the same contents.

    For most Java types, including String, Clojure = dispatches to Java .equals. String.equals is defined as "represents the same sequence of characters."

    If you want to test identity (Are these pointers to the same location in memory?) use the identical? function.

提交回复
热议问题