store/[org.clojure/clojure "1.8.0"] clj::clojure.core/into-array

Official Documentation

Add notes
Arities
==================================================
   [aseq]
   [type aseq]

Docstring
==================================================
  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.

Source

(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))))

Example 1

Edit
;; Creating an empty array defaults to Object[]
(into-array [])
;; => #<Object[] [Ljava.lang.Object;@21f1151f>

;; However, the type of an empty array can be coerced
(into-array String [])
;; => #<String[] [Ljava.lang.String;@578baf24>

Example 2

Edit
;; java.nio.file.Paths#get takes (String, String...)
(java.nio.file.Paths/get "/Users" (into-array ["username" "dev" "clojure"]))
;; => #<UnixPath /Users/username/dev/clojure>

Example 3

Edit
;; Array's component type is set to (class 2), cannot add Strings.
;; This will result in an IllegalArgumentException
(into-array [2 "4" "8" 5])
;; Evaluation aborted.

;; However, if the common type is specified, aforementioned values can be put into an array
(into-array Object [2 "4" "8" 5])
;; => #<Object[] [Ljava.lang.Object;@3aa6d0a4>

(into-array (range 4))
;; => #<Integer[] [Ljava.lang.Integer;@63d6dc46>

;; if you assign a type, you still have to coerce values
(into-array Byte/TYPE (range 4))
;; Evaluation aborted.

(into-array Byte/TYPE (map byte (range 4)))
;; => #<byte[] [B@68ffefc9>

Uses on crossclj