---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 16 Edition"
java_version: 16
chapter: "Chapter 6. The Java Virtual Machine Instruction Set"
section: "6.5.anewarray"
heading: "anewarray"
parent: "6.5. Instructions"
source: https://docs.oracle.com/javase/specs/jvms/se16/html/jvms-6.html#jvms-6.5.anewarray
id: "6.5.anewarray"
url: https://jvm.obfuscated.software/jvms/se16/6.5.anewarray.html
raw: https://jvm.obfuscated.software/jvms/se16/6.5.anewarray.md
---

# anewarray

## Operation

Create new array of `reference`

## Format

```
anewarray
indexbyte1
indexbyte2
```

## Forms

anewarray = 189 (0xbd)

## Operand Stack

..., *count* →

..., *arrayref*

## Description

The *count* must be of type `int`. It is popped off the operand stack. The *count* represents the number of components of the array to be created. The unsigned *indexbyte1* and *indexbyte2* are used to construct an index into the run-time constant pool of the current class ([§2.6](2.6.md)), where the value of the index is (*indexbyte1* `<<` 8) | *indexbyte2*. The run-time constant pool entry at the index must be a symbolic reference to a class, array, or interface type. The named class, array, or interface type is resolved ([§5.4.3.1](5.4.3.1.md)). A new array with components of that type, of length *count*, is allocated from the garbage-collected heap, and a `reference` *arrayref* to this new array object is pushed onto the operand stack. All components of the new array are initialized to `null`, the default value for `reference` types ([§2.4](2.4.md)).

## Linking Exceptions

During resolution of the symbolic reference to the class, array, or interface type, any of the exceptions documented in [§5.4.3.1](5.4.3.1.md) can be thrown.

## Run-time Exceptions

Otherwise, if *count* is less than zero, the *anewarray* instruction throws a `NegativeArraySizeException`.

## Notes

The *anewarray* instruction is used to create a single dimension of an array of object references or part of a multidimensional array.
