IntBuffer
is a class in Java that is defined inside the java.nio
package. The java.nio
package defines buffers, which are a chunk of readable and writeable memory that can be used to easily communicate over NIO channels. There are many types of buffers in the java.nio
package, including IntBuffer
. IntBuffer
is similar to arrays of different data types with different sizes.
The class IntBuffer
allows for various operations, which are as follows:
The reset()
method in Java resets the position to the one previously marked using the mark
method. The position in an IntBuffer
refers to the index being pointed to.
There is no mandatory parameter for the reset()
method.
The reset()
method returns the buffer.
The following example will help you understand the reset()
method better. First, we create an array of type int
and use the wrap
method to create an IntBuffer
. Then, we set the position of the index using the position
method and mark it using the mark
method. We change the position of the index and print the current position. Lastly, we use the reset
method to reset the current position of the index to the one we marked and print it.
import java.nio.*;import java.util.*;public class EX{public static void main(String[] args){int[] intarray = {1,2,3,4};IntBuffer buff = IntBuffer.wrap(intarray);buff.position(1);buff.mark();buff.position(3);System.out.println("Position before using reset() method: "+ buff.position());buff.reset();System.out.println("Position after using reset() method: "+ buff.position());}}
Free Resources