LongBuffer array() in Java

array(): This method is available in java.nio.LongBuffer class of Java.

Syntax:

long[] java.nio.LongBuffer.array()

This method returns the long array that backs this buffer.

Parameters: NA

Returns: The array that backs this buffer.

Throws:

1. ReadOnlyBufferException - If this buffer is backed by an array but is read-only.

2. UnsupportedOperationException - If this buffer is not backed by an accessible array

Approach

Java


import java.nio.LongBuffer;
import java.util.Arrays;

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

        long array[] = { 1, 2, 3, 4 };
        LongBuffer lb = LongBuffer.wrap(array);

        System.out.println(Arrays.toString(lb.array()));
    }
}

Output:

[1, 2, 3, 4]

No comments:

Post a Comment