The hasArray() method of the DoubleBuffer class is used to determine whether a buffer is backed by an accessible array. It returns true when the buffer is backed by an accessible array and is not read-only; otherwise, it returns false.
In this chapter, you will learn about the DoubleBuffer.hasArray() method, its syntax, return value, and how it behaves with normal and read-only buffers.
The hasArray() method of the DoubleBuffer class checks whether the buffer is backed by an accessible double array. If the buffer is not read-only and its backing array is accessible, the method returns true.
When the method returns true, the array() and arrayOffset() methods can be used to access information about the backing array. For a read-only buffer or a buffer whose backing array is not accessible, the method returns false.
The syntax of the hasArray() method is:
public final boolean hasArray()
The hasArray() method returns true if the buffer is backed by an accessible array and is not read-only. Otherwise, it returns false.
Here, we are going to take several examples that demonstrate the working of the DoubleBuffer hasArray() Method.
The following example creates a DoubleBuffer using allocate() and checks whether the buffer is backed by an accessible array using the hasArray() method.
Output:
DoubleBuffer doublebuff is backed by the array
The following example creates a read-only view of a DoubleBuffer using asReadOnlyBuffer() and uses the hasArray() method to check whether its backing array is accessible.
A read-only buffer does not provide access to its backing array through the array() method, so hasArray() returns false.
Output:
DoubleBuffer doublebuff is not backed by any of the array
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India