LongBuffer hasArray() method in Java Last Updated : 19 Sep, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The array() method of java.nio.LongBuffer Class is used to Return the Long array that backs this buffer. Modifications to this buffer's content will cause the returned array's content to be modified, and vice versa. Invoke() the hasArray() method are used before invoking this method in order to ensure that this buffer has an accessible backing array Syntax : public final Long[] array() Return Value: This method returns the array that backs this buffer. Throws: This method throws the ReadOnlyBufferException(If this buffer is backed by an array but is read-only) Below program illustrates the array() method: Examples 1: Java // Java program to demonstrate // array() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the capacity of the LongBuffer int capacity = 10; // Creating the LongBuffer try { // creating object of Longbuffer // and allocating size capacity LongBuffer ib = LongBuffer.allocate(capacity); // putting the value in Longbuffer ib.put(7); ib.put(2, 6); ib.rewind(); // getting array from ib LongBuffer using array() method long[] ibb = ib.array(); // prLonging the LongBuffer ib System.out.println("LongBuffer: " + Arrays.toString(ibb)); } catch (IllegalArgumentException e) { System.out.println("IllegalArgumentException catched"); } catch (ReadOnlyBufferException e) { System.out.println("ReadOnlyBufferException catched"); } } } Examples 2: Java // Java program to demonstrate // array() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the capacity of the ib int capacity1 = 10; // Declaring the capacity of the ib1 int capacity2 = 5; // Creating the LongBuffer try { // // ib // // creating object of Longbuffer ib // and allocating size capacity LongBuffer ib = LongBuffer.allocate(capacity1); // putting the value in ib ib.put(7); ib.put(2, 6); ib.put(3, 7); ib.rewind(); // prLong the LongBuffer System.out.println("LongBuffer ib: " + Arrays.toString(ib.array())); // // ib1 // // creating object of Longbuffer ib1 // and allocating size capacity LongBuffer ib1 = LongBuffer.allocate(capacity2); // putting the value in ib1 ib1.put(1, 4); ib1.put(2, 6); ib1.rewind(); // prLong the LongBuffer System.out.println("\nLongBuffer ib1: " + Arrays.toString(ib1.array())); // Creating a read-only copy of LongBuffer // using asReadOnlyBuffer() method LongBuffer readOnlyib = ib.asReadOnlyBuffer(); // prLong the LongBuffer System.out.print("\nReadOnlyBuffer LongBuffer: "); while (readOnlyib.hasRemaining()) System.out.print(readOnlyib.get() + ", "); // try to change readOnlyib System.out.println("\n\nTrying to get the array" + " from ReadOnlyib for editing"); long[] ibarr = readOnlyib.array(); } catch (IllegalArgumentException e) { System.out.println("IllegalArgumentException catched"); } catch (ReadOnlyBufferException e) { System.out.println("Exception thrown: " + e); } } } Comment More infoAdvertise with us Next Article LongBuffer get() methods in Java P pawan_asipu Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-LongBuffer +1 More Practice Tags : JavaMisc Similar Reads LongBuffer arrayOffset() method in Java The arrayOffset() method of java.nio.LongBuffer class is used to return the offset within the buffer's backing array of the first element of the buffer. It means that if this buffer is backed by an array, then buffer position p corresponds to array index p + arrayOffset(). In order to check whether 3 min read LongBuffer equals() method in Java The equals() method of java.nio.LongBuffer Class is used to check whether or not the given buffer is equal to another object. Two Long buffers are equal if, and only if, They have the same element type, They have the same number of remaining elements, and The two sequences of remaining elements, con 4 min read LongBuffer allocate() method in Java The allocate() method of java.nio.LongBuffer Class is used to allocate a new Long buffer next to the existing buffer. The new buffer's position will be zero. Its limit will be its capacity. Its mark will be undefined. And each of its elements will be initialized to zero. It will have a backing array 2 min read LongBuffer get() methods in Java get() The get() method of java.nio.LongBuffer Class is used to read the Long at the given buffer's current position, and then increment the position. Syntax : public abstract Long get() Return Value: This method returns the Long value at the buffer's current position. Throws: This method throws Buff 5 min read IntBuffer hasArray() method in Java The hasArray() method of java.nio.IntBuffer class is used to ensure whether or not the given buffer is backed by an accessible int array. It returns true if there is an accessible backing array to this buffer, else it returns false. If this method returns true, then the array() and arrayOffset() met 2 min read LongBuffer wrap() method in Java wrap(Long[] array) The wrap() method of java.nio.LongBuffer Class is used to wrap a Long array, Longo, a buffer. The new buffer will be backed by the given Long array; that is, modifications to the buffer will cause the array to be modified and vice versa. The new buffer's capacity and limit will be 4 min read Like