Buffer position() methods in Java with Examples
The position(int newPosition) method of java.nio.Buffer Class is used to set this buffer’s position. If the mark is defined and larger than the new position then it is discarded.
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.
public Buffer 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
position before clear: 3 position after clear: 0