CharBuffer position() methods in Java with Examples
The position(int newPosition) method of java.nio.CharBuffer Class is used to set this buffer’s position. If the mark is defined and larger than the new position then it is discarded.
public CharBuffer 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
CharBuffer: [, x,, y]
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.