to-array

added
1.0

ns
clojure.core

type
function

(to-array coll)

Returns an array of Objects containing the contents of coll, which
can be any Collection.  Maps to java.util.Collection.toArray().

                user=> (to-array [1 2 3])
#<Object[] [Ljava.lang.Object;@b2bb14>
            
                (def hello (to-array "Hello World!"))

(aget hello 1)
;; => \\e

(aset hello 1 \\b) ;;Mutability! Watch out!
;; => \\b

(dotimes [n (alength hello)] (print (aget hello n)))
;; => Hbllo World!

;; Calling `to-array` on array returns the original, not a copy
(identical? (to-array hello) hello)
;; => true