VOOZH about

URL: https://www.geeksforgeeks.org/java/bytebuffer-reset-methods-in-java-with-examples/

⇱ ByteBuffer reset() methods in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ByteBuffer reset() methods in Java with Examples

Last Updated : 16 Jul, 2019
The reset() method of java.nio.ByteBuffer Class is used to reset this buffer's position to the previously-marked position. Invoking this method neither changes nor discards the mark's value. Syntax:
public ByteBuffer reset()
Return Value: This method returns this buffer. Below are the examples to illustrate the reset() method: Examples 1:
Output:
position before reset: 4
position after reset: 2
Examples 2:
Output:
position before reset: 1

new position is less than the position we marked before 
Exception throws: java.nio.InvalidMarkException
Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/ByteBuffer.html#reset--
Comment