The IntBuffer mark()
method sets the current position of an integer buffer as its mark.
The program needs to import the following module to use the IntBuffer mark()
method:
java.nio.IntBuffer
The IntBuffer mark()
method accepts no parameters and returns an integer buffer with a mark at the current position.
The following example shows how to use the IntBuffer mark()
method in Java:
IntBuffer wrap
function.// Java program to demonstrate// mark() methodimport java.nio.*;import java.util.*;public class main {public static void main(String[] args){try {int[] arr = { 11,22,33,44,55,66 };//create an Int BufferIntBuffer buf = IntBuffer.wrap(arr);//set position to index 3buf.position(3);//set the current position as the buffer's markbuf.mark();// try to set the position at index 2buf.position(5);// display positionSystem.out.println("position before reset: "+ buf.position());//reset will set the position to markbuf.reset();// display positionSystem.out.println("position after reset: " + buf.position());}catch (InvalidMarkException e) {System.out.println("New postion is less than the previous position");System.out.println("Exception throws: "+ e);}}}
Free Resources