2

to-array-2D is a handy function for converting a collection of collections into a 2D java array. Is there a function to go the other way?

I would like to get a vector of vectors from a 2D java array.

3
  • 1
    Maybe something like (mapv (partial into []) my-array) Commented Oct 10, 2015 at 15:33
  • good enough for me! thanks! post an answer and i'll upvote Commented Oct 10, 2015 at 15:35
  • It's ok. You've already got a better answer Commented Oct 10, 2015 at 17:20

1 Answer 1

4

You could do:

(mapv vec the-array)

Although in that case, take into account the documentation of vec

clojure.core/vec
([coll])
Creates a new vector containing the contents of coll. Java arrays
will be aliased and should not be modified.

If you prefer to make a copy (less efficient but safer), do what leeor says in the comment. Shorter version:

(mapv #(into [] %) the-array)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.