DoubleBuffer array() method in Java With Examples
The array() method of java.nio.DoubleBuffer Class is used to Return the double 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
public final float array()
Return Value: This method returns the array that backs this buffer.
Exception: This method throws the ReadOnlyBufferException if this buffer is backed by an array but is read-only.
Below program illustrates the array() method:
DoubleBuffer: [8.5600004196167, 0.0, 9.609999656677246, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
DoubleBuffer db: [9.5600004196167, 0.0, 7.610000133514404, 4.610000133514404, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] DoubleBuffer db1: [0.0, 4.559999942779541, 6.449999809265137, 0.0, 0.0] ReadOnlyBuffer DoubleBuffer: 9.5600004196167, 0.0, 7.610000133514404, 4.610000133514404, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Trying to get the array from ReadOnlyDb for editing Exception thrown: java.nio.ReadOnlyBufferException
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.