Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

clojure
java interface
java
string
communitycreator

How to use Java methods on strings in Clojure

Chinweuba Elijah Azubuike

Overview

Since Clojure ends up running on a Java virtual environment, it is no surprise that we can utilize some of its methods.

Use Java methods on strings in Clojure

We can do this using the dot notation followed by the method we want to use. Let's see an example.

Example

(ns Project
   (:gen-class))
(defn func []
   (println (.toUpperCase "Hello World")))
(func)
An example of using Java methods in Clojure

Explanation

  • Line 3: We create a function, func .
  • Line 4: We use the toUpperCase Java method. This method converts a text in a string into capital letters.
  • Line 5: We call our func function.

RELATED TAGS

clojure
java interface
java
string
communitycreator

CONTRIBUTOR

Chinweuba Elijah Azubuike
RELATED COURSES

View all Courses

Keep Exploring