Creating an empty string array

1,082 views
Skip to first unread message

Konrad Hinsen

unread,
Mar 28, 2011, 3:58:13 PM3/28/11
to Clojure
For interfacing with some Java code I need to create an empty string
array in Clojure. Is that possible somehow? The only way I know to
create a string array is

(into-array ["a" "b"])

but

(into-array [])

creates of course an object array.

Konrad.

Alan

unread,
Mar 28, 2011, 4:06:17 PM3/28/11
to Clojure
(into-array String [])

(make-array String 0)

Max Penet

unread,
Mar 28, 2011, 4:11:24 PM3/28/11
to Clojure
into-array can do that for you:

user=> (doc into-array)
-------------------------
clojure.core/into-array
([aseq] [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.
nil


user=> (into-array String [])
#<String[] [Ljava.lang.String;@51c888d9>

Konrad Hinsen

unread,
Mar 29, 2011, 2:32:24 AM3/29/11
to clo...@googlegroups.com
On 28 Mar 2011, at 22:06, Alan wrote:

> (into-array String [])
>
> (make-array String 0)

Thanks!

Konrad.

Reply all
Reply to author
Forward
0 new messages