Calling Apache Commons Text CaseUtils from Clojure

I installed Apache Commons Text in my Leiningen project:

:dependencies [[org.clojure/clojure "1.11.1"]
               [org.apache.commons/commons-text "1.13.0"]]

Now I try to convert kebab-case to CamelCase from the REPL:

(import org.apache.commons.text.CaseUtils)
(CaseUtils/toCamelCase "foo-bar" false (to-array [\-]))

But I get this error message:

Execution error (ClassCastException) at interop.core/eval11241 (REPL:116).
class [Ljava.lang.Object; cannot be cast to class [C ([Ljava.lang.Object; and [C are in module java.(import org.apache.commons.text.CaseUtils)

According to the documentation, I have to pass the delimiters as an array (i.e. varargs).

What am I doing wrong?

to-array creates an object array, but you need a character array. Try using char-array instead.

1 Like

Thanks, that did solve my issue!