Clojure – Strings compare

Clojure strings compare

In this guide, we will discuss 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

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply