Arrays vs vectors

Deephaven tables can store multi-element data in two forms: Java primitive arrays and Deephaven vectors. While both represent ordered collections of elements, they have important differences that affect how you work with them.

Quick comparison

FeatureJava ArraysDeephaven Vectors
Type examplesint[], double[], String[]IntVector, DoubleVector, ObjectVector
Index typeint (max ~2.1 billion elements)long (supports larger datasets)
Out-of-bounds accessThrows exceptionReturns null constant (e.g., NULL_INT)
Created byExplicit constructionTable operations (groupBy, rolling ops)
Memory modelOwns contiguous memoryMay be a view into table data
SlicingArrays.copyOfRangesubVector (no copy)

Java primitive arrays

Java arrays are standard fixed-size collections. Create them explicitly using Java syntax:

Java arrays use int-based indexing. Accessing an index outside the array bounds throws an ArrayIndexOutOfBoundsException.

Deephaven vectors

Deephaven vectors are Deephaven's specialized collection type, implemented by the Vector interface and its subclasses (IntVector, DoubleVector, etc.). Table operations that group data produce vector columns:

The Y column is an IntVector, not an int[].

Key advantages of vectors

Long-based indexing: Vectors use long indices, supporting datasets larger than 2.1 billion elements.

Safe out-of-bounds access: Accessing an invalid index returns the appropriate null constant rather than throwing an exception:

Efficient slicing: The subVector method creates a view without copying data:

Column access with underscore: Access any column as a vector using the _ suffix:

Converting between arrays and vectors

Use the built-in array and vec functions to convert between types:

Supported conversions

vec() inputarray() input
byte[]ByteVector
char[]CharVector
double[]DoubleVector
float[]FloatVector
int[]IntVector
long[]LongVector
short[]ShortVector

Choosing between arrays and vectors

Use Java arrays when:

  • Passing data to external Java libraries that expect arrays
  • Working with fixed, known-size data
  • You need to mutate elements in place.

Use Deephaven vectors when:

  • Working with grouped table data.
  • Accessing previous or future row values via Column_[ii ± n].
  • Slicing data without copying.
  • Handling potentially large datasets.

Operations that create vectors

The following table operations produce vector columns: