You're viewing version 1.2.0 of to-array. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

to-array

clojure.core

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

2 Examples top

  • user=> (to-array [1 2 3])
    #<Object[] [Ljava.lang.Object;@3a7e479a>
    
  • (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!
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:295 top

(defn to-array
  "Returns an array of Objects containing the contents of coll, which
  can be any Collection.  Maps to java.util.Collection.toArray()."
  {:tag "[Ljava.lang.Object;"
   :added "1.0"}
  [coll] (. clojure.lang.RT (toArray coll)))
Vars in clojure.core/to-array: defn

Comments top

No comments for to-array. Log in to add a comment.