get(): This method is available in java.nio.IntBuffer class of Java.
Syntax:
int java.nio.IntBuffer.get()
This method reads the int at this buffer'scurrent position and then increments the position.
Parameters: NA
Returns: The int at the buffer's current position.
Throws:
BufferUnderflowException - If the buffer's current position is not smaller than its limit.
Approach 1: When no exceptions
Java
import java.nio.IntBuffer;public class IntBufferget {public static void main(String[] args) {int array[] = { 12, 34, 56, 78 };IntBuffer lb = IntBuffer.wrap(array);System.out.println(lb.get());}}
Output:
12
Approach 2: BufferUnderflowException
Java
import java.nio.IntBuffer;public class IntBufferget {public static void main(String[] args) {int array[] = {};IntBuffer lb = IntBuffer.wrap(array);System.out.println(lb.get());}}
Output:
Exception in thread "main" java.nio.BufferUnderflowException at java.base/java.nio.Buffer.nextGetIndex(Buffer.java:694) at java.base/java.nio.HeapIntBuffer.get(HeapIntBuffer.java:166)
Some more get methods.
No comments:
Post a Comment