0

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?

1
  • this is how i call .split: (.split "1,2,3,4,5" ",") Commented Nov 3, 2015 at 13:26

2 Answers 2

3

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"]
Sign up to request clarification or add additional context in comments.

Comments

2

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

how could i invoke the whole resulting elements as a sequence? Is there a built-in function? I assume aget let me access the elements only via index?
@AmirTeymuri The link I provided explains aget.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.