into-array

clojure.core

  • (into-array aseq)
  • (into-array type aseq)
Returns an array with components set to the values in aseq. The array's
component type is type if provided, or the type of the first value in
aseq if present, or Object. All values in aseq must be compatible with
the component type. Class objects for the primitive types can be obtained
using, e.g., Integer/TYPE.

1 Example top

  • ;; Java doesn't support heterogeneous arrays
    ;; this will result in an IllegalArgumentException
    user=> (into-array [2 "4" "8" 5])
    ;; Evaluation aborted.
    
    user=> (into-array (range 4))
    #<Integer[] [Ljava.lang.Integer;@63d6dc46>
    
    ;; if you assign a type, you still have to coerce values
    user=> (into-array Byte/TYPE (range 4))
    ;; Evaluation aborted.
    
    user=> (into-array Byte/TYPE (map byte (range 4)))
    #<byte[] [B@68ffefc9>
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:3029 top

(defn into-array
  "Returns an array with components set to the values in aseq. The array's
  component type is type if provided, or the type of the first value in
  aseq if present, or Object. All values in aseq must be compatible with
  the component type. Class objects for the primitive types can be obtained
  using, e.g., Integer/TYPE."
  {:added "1.0"
   :static true}
  ([aseq]
     (clojure.lang.RT/seqToTypedArray (seq aseq)))
  ([type aseq]
     (clojure.lang.RT/seqToTypedArray type (seq aseq))))
Vars in clojure.core/into-array:
Used in 0 other vars

Comments top

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