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() method import 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 Buffer IntBuffer buf = IntBuffer.wrap(arr); //set position to index 3 buf.position(3); //set the current position as the buffer's mark buf.mark(); // try to set the position at index 2 buf.position(5); // display position System.out.println("position before reset: "+ buf.position()); //reset will set the position to mark buf.reset(); // display position System.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); } } }
RELATED TAGS
CONTRIBUTOR
View all Courses