When i call the .split methode in clojure i get: #object["[Ljava.lang.String;" 0x5aaf6982 "[Ljava.lang.String;@5aaf6982"] #object["[Ljava.lang.String;" 0x18fbbda2 "[Ljava.lang.String;@18fbbda2"].
How can i use this object in my code?
2 Answers
You can use vec to convert a Java array into a vector, e.g.
(vec (.split "1,2,3,4,5" ","))
=> ["1" "2" "3" "4" "5"]
But really if you want to split a string into a Clojure collection you should be using clojure.string/split instead:
(clojure.string/split "1,2,3,4,5" #",")
=> ["1" "2" "3" "4" "5"]
Comments
Assuming that you are using .split method of Java String class, then the result is a Java array.
You can use aget function of Clojure to access the elements.
And depending on your use case, it might be better to convert the array into Clojure sequence, so you can use a vast array of functions that Clojure provides to manipulate sequences.
2 Comments
Chiron
@AmirTeymuri The link I provided explains
aget.
.split:(.split "1,2,3,4,5" ",")