Clojure - Strings compare



Returns a negative number, zero, or a positive number when ‘x’ is logically 'less than', 'equal to', or 'greater than' ‘y’. It is similar to Java x.compareTo(y) except it also works for nil, and mpares numbers and collections in a type-independent manner.

Syntax

Following is the syntax.

(compare x y)

Parameters − Where x and y are the 2 strings which need to be compared.

Return Value − Returns a negative number, zero, or a positive number when ‘x’ is logically 'less than', 'equal to', or 'greater than' ‘y’.

Example

Following is an example of the string formatting in Clojure.

(ns clojure.examples.hello
   (:gen-class))
(defn hello-world []
   (println (compare "Hello" "hello"))
   (println (compare "Hello" "Hello")))
(hello-world)

Output

The above program produces the following output.

-32
0
clojure_strings.htm
Advertisements