DoubleBuffer hasArray() method in Java with Examples

Last Updated : 13 Oct 2026

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.

What is DoubleBuffer hasArray() Method in Java?

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.

Syntax of DoubleBuffer hasArray() Method

The syntax of the hasArray() method is:

public final boolean hasArray()

Return Value

The hasArray() method returns true if the buffer is backed by an accessible array and is not read-only. Otherwise, it returns false.

Examples of DoubleBuffer hasArray() Method

Here, we are going to take several examples that demonstrate the working of the DoubleBuffer hasArray() Method.

Example 1: Checking Whether DoubleBuffer is Backed by an Array

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   

Example 2: Checking hasArray() for a Read-Only DoubleBuffer

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   

Next TopicJava Logger