The
position(int newPosition) method of
java.nio.ByteBuffer Class is used to Sets this buffer's position. If the mark is defined and larger than the new position then it is discarded.
Syntax:
public ByteBuffer position(int newPosition)
Parameters: This method takes the
newPosition as parameter which is the new position value. It must be non-negative and no larger than the current limit.
Return Value: This method returns this buffer.
Below are the examples to illustrate the
position() method:
Examples 1:
Output:
position before reset: 4
position after reset: 2
Examples 2: