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

# swap

## Operation

Swap the top two operand stack values

## Format

```
swap
```

## Forms

*swap* = 95 (0x5f)

## Operand Stack

..., *value2*, *value1* →

..., *value1*, *value2*

## Description

Swap the top two values on the operand stack.

The *swap* instruction must not be used unless *value1* and *value2* are both values of a category 1 computational type ([§2.11.1](2.11.1.md)).

## Notes

The Java Virtual Machine does not provide an instruction implementing a swap on operands of category 2 computational types.
