Module java.base
Package java.nio

Class ShortBuffer

java.lang.Object
java.nio.Buffer
java.nio.ShortBuffer
All Implemented Interfaces:
Comparable<ShortBuffer>

public abstract sealed class ShortBuffer extends Buffer implements Comparable<ShortBuffer>
A short buffer.

This class defines four categories of operations upon short buffers:

  • Absolute and relative get and put methods that read and write single shorts;

  • Absolute and relative bulk get methods that transfer contiguous sequences of shorts from this buffer into an array;

  • Absolute and relative bulk put methods that transfer contiguous sequences of shorts from a short array or some other short buffer into this buffer;

  • A method for compacting a short buffer.

Short buffers can be created either by allocation, which allocates space for the buffer's content, by wrapping an existing short array into a buffer, or by creating a view of an existing byte buffer.

Like a byte buffer, a short buffer is either direct or non-direct. A short buffer created via the wrap methods of this class will be non-direct. A short buffer created as a view of a byte buffer will be direct if, and only if, the byte buffer itself is direct. Whether or not a short buffer is direct may be determined by invoking the isDirect method.

Methods in this class that do not otherwise have a value to return are specified to return the buffer upon which they are invoked. This allows method invocations to be chained.

Optional operations

Methods specified as optional operations throw a ReadOnlyBufferException when invoked on a read-only ShortBuffer. The methods array and arrayOffset throw an UnsupportedOperationException if the ShortBuffer is not backed by an accessible short array (irrespective of whether the ShortBuffer is read-only).
Since:
1.4