Push int
constant 0, 1, 2, 3, 4 or 5
Bytecode
Type | Description |
u1 | iconst_0 opcode = 0x03 (3) |
u1 | iconst_1 opcode = 0x04 (4) |
u1 | iconst_2 opcode = 0x05 (5) |
u1 | iconst_3 opcode = 0x06 (6) |
u1 | iconst_4 opcode = 0x07 (7) |
u1 | iconst_5 opcode = 0x08 (8) |
Push the int
constant <i> (-1, 0, 1, 2,
3, 4 or 5) onto the operand stack. For example, to push the int zero
onto the stack, use:
iconst_0 ; push 0 onto the stack.
Note that you could also use:
bipush 0 ; push 0 onto the stack
or
sipush 0 ; push 0 onto the stack
or
ldc 0 ; push 0 onto the stack
although these instructions are typically less efficient than the equivalent iconst_<n> and also take up more bytes in the class file.
Each of this family of instructions is equivalent to bipush <i> for the respective value of <i>, except that the operand <i> is implicit.
iconst_0 ; push 0 onto the stack iconst_1 ; push 1 onto the stack iconst_2 ; push 2 onto the stack iconst_3 ; push 3 onto the stack iconst_4 ; push 4 onto the stack iconst_5 ; push 5 onto the stack