newarray 0xbc
Pops a length; pushes a new array of a primitive type.
- Opcode
0xbc(188)- Family
- Arrays
- Operands
- 1 byte: array type (4–11)
- Length
- 2 bytes
- Operand stack
…, count (int) → …, arrayref- Can throw
NegativeArraySizeException
What it does
Creates an array of a primitive type with every element zero (or false). The operand byte is the element type: 4 boolean, 5 char, 6 float, 7 double, 8 byte, 9 short, 10 int, 11 long.
javac also uses it for array initialisers such as {1, 2, 3}: newarray, then a dup, an index, a value and a store for each element. A varargs call builds its array the same way.
How often javac uses it
In JDK 25.0.5's java.base module, newarray appears 3,063 times in 809 of its 7,391 classes: 0.16% of all instructions, the 73rd most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.getBufIfOpen, java.io.BufferedOutputStream.<init>, java.io.BufferedReader.<init>, java.io.BufferedWriter.<init>.
Examples
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; newarray is highlighted.
static { … } in EnumSwitch.1, compiled by javac 25static int callers() in Varargs, compiled by javac 25Related instructions
anewarray Pops a length; pushes a new array of references.multianewarray Pops several lengths; pushes a new multi-dimensional array.arraylength Pops an array; pushes its length.
Specification: JVMS §6.5, newarray (Java SE 25).