Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

clojure
java
parameters
methods
communitycreator

How to call Java methods with parameters in Clojure

Chinweuba Elijah Azubuike

Overview

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

How to call Java methods with parameters in Clojure

We can use the dot notation followed by the method we want to use, passing the parameter. Let's see an example.

Example

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

Explanation

Line 3: We create a function, func.

Line 4: We use the indexOf method to find the index of a letter in a string, and we find the index of the letter e.

Line 5: We call our function func.

RELATED TAGS

clojure
java
parameters
methods
communitycreator

CONTRIBUTOR

Chinweuba Elijah Azubuike
RELATED COURSES

View all Courses

Keep Exploring