IntBuffer get(int[]) in Java

get(int[]): This method is available in java.nio.IntBuffer class of Java.

Syntax:

IntBuffer java.nio.IntBuffer.get(int[] dst)

This method takes one argument of type int array as its parameter. This method transfers ints from this buffer into the given destination array.

Parameters: One parameter is required for this method.

dst: The destination array.

Returns: This buffer.

Throws:

BufferUnderflowException - If there are fewer than length ints remaining in this buffer.

Approach 1: When no exceptions.

Java

import java.nio.IntBuffer;

public class IntBufferget3 {
    public static void main(String[] args) {

        int array[] = { 1, 2, 78, 1991, 18 };
        IntBuffer lb = IntBuffer.wrap(array);

        int dst[] = { 1, 2, 3 };
        System.out.println(lb.get(dst));
    }
}

Output:

java.nio.HeapIntBuffer[pos=3 lim=5 cap=5]


Approach 2: BufferUnderflowException 

Java

import java.nio.IntBuffer;

public class IntBufferget3 {
    public static void main(String[] args) {

        int array[] = { 1, 2 };
        IntBuffer lb = IntBuffer.wrap(array);

        int dst[] = { 1, 2, 3 };
        System.out.println(lb.get(dst));
    }
}

Output:

Exception in thread "main" java.nio.BufferUnderflowException at java.base/java.nio.HeapIntBuffer.get(HeapIntBuffer.java:185) at java.base/java.nio.IntBuffer.get(IntBuffer.java:814)


Some more get methods.


get()


get(int)


get(int, int[])


get(int[], int, int)


get(int, int[], int, int)


No comments:

Post a Comment