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.
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:
position before reset: 4 position after reset: 2
ByteBuffer: [0, 10, 0, 30]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.