Skip to content

clojure.core/byte-array

View this page on ClojureDocs

Type: function Added: Clojure 1.1 Examples: 3 Runnable: 0
([size-or-seq] [size init-val-or-seq])

Creates an array of bytes

Examples

by shockbob on . May have evaluation errors.
by guruma on . May have evaluation errors.
by nivekuil on . May have evaluation errors.

Note by dspearson

The maximum size of a byte-array is Integer/MAX_VALUE, as arrays are int-indexed in Java. However, it is possible to pass a value that is larger than this, resulting in a cast that will wrap around. This incorrect usage will not give any indication of error.

Note by luposlip

To type hint a byte array, use this non-obvious syntax:

(.write ^OutputStream output-stream ^"[B" bytearray)

Note by brunchboy

You can also use ^bytes to type hint a byte array, and as of Clojure 1.12, ^byte/1 for a one-dimensional byte array, ^byte/2 for two dimensions, etc.

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.