Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java

What is the floatBuffer array() method in Java?

Sarvech Qadir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The array() method is part of the class java.nio.FloatBuffer. This method returns a float array from the float buffer instance. This array contains all the modified contents of the float buffer.

Syntax

floatBuffer.array();

Return value

array() returns the float datatype array.

Using this method can throw the ReadOnlyBufferException if the buffer is read-only.

Code

The code below provides an example of the array() method.

import java.nio.*;
import java.util.*;
class HelloWorld {
public static void main( String args[] ) {
// initializing a float buffer by allocating memory
FloatBuffer buff = FloatBuffer.allocate(5);
// put values in floatBuffer using put() method
buff.put(23.2F);
buff.put(21.7F);
// applying the array method
float[] buffer = buff.array();
// printing the FloatBuffer
System.out.println("FloatBuffer: "+ Arrays.toString(buffer));
// exploring changes in buffer, we add another value. The array
// is changed accordingly
buff.put(12.0F);
System.out.println("FloatBuffer: "+ Arrays.toString(buffer));
}
}

RELATED TAGS

java

CONTRIBUTOR

Sarvech Qadir
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring