The jarray module exports two functions:
array(sequence, type) zeros(length, type)
array will create a new array of the same length as the input sequence and will populate it with the values in sequence. zeros will create a new array of the given length filled with zeros (or null's if appropriate).
type can either be a single character typecode (using the same mappings as Python's array module) or it can be an instance of a JavaClass object. The valid typecodes are shown in the following table:
| Character Typecode | Corresponding Java Type |
|---|---|
| z | boolean |
| c | char |
| b | byte |
| h | short |
| i | int |
| l | long |
| f | float |
| d | double |
>>> from jarray import zeros, array >>> array([1,2,3], 'd') array([1.0, 2.0, 3.0], double) >>> zeros(3, 'f') array([0.0, 0.0, 0.0], float) >>> from java.util import Hashtable >>> array([Hashtable(), Hashtable()], Hashtable) array([<java.util.Hashtable instance at 2045730>, <java.util.Hashtable instance at 2045714>], java.util.Hashtable) >>> zeros(5, Hashtable) array([None, None, None, None, None], java.util.Hashtable)This example show how to create an array of three specific doubles, a length-three array of floats, an array of two specific instance of java.util.Hashtable, and an empty array of java.util.Hashtable's.