- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
FloatBuffer wrap() method in Java
A float array can be wrapped into a buffer using the method wrap() in the class java.nio.FloatBuffer. This method requires a single parameter i.e. the array to be wrapped into a buffer and it returns the new buffer created. If the returned buffer is modified, then the contents of the array are also similarly modified and vice versa.
A program that demonstrates this is given as follows −
Example
import java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { try { float[] arr = { 8.7F, 1.5F, 3.2F, 7.4F, 5.9F }; System.out.println("The array length is: " + arr.length); System.out.println("Array elements are: " + Arrays.toString(arr)); FloatBuffer buffer = FloatBuffer.wrap(arr); buffer.rewind(); System.out.println("
The FloatBuffer is: " + Arrays.toString(buffer.array())); System.out.println("The position is: " + buffer.position()); System.out.println("The capacity is: " + buffer.capacity()); } catch (IllegalArgumentException e) { System.out.println("Error!!! IllegalArgumentException"); } catch (ReadOnlyBufferException e) { System.out.println("Error!!! ReadOnlyBufferException"); } } }
The output of the above program is as follows −
Output
The array length is: 5 Array elements are: [8.7, 1.5, 3.2, 7.4, 5.9] The FloatBuffer is: [8.7, 1.5, 3.2, 7.4, 5.9] The position is: 0 The capacity is: 5
- Related Articles
- FloatBuffer compareTo() method in Java
- FloatBuffer allocate() method in Java
- FloatBuffer compact() method in Java
- FloatBuffer arrayOffset() method in Java
- FloatBuffer hasArray() method in Java
- FloatBuffer slice() method in Java
- FloatBuffer get() method in Java
- FloatBuffer put() method in Java
- FloatBuffer array() method in Java
- FloatBuffer equals() method in Java
- FloatBuffer duplicate() method in Java
- FloatBuffer asReadOnlyBuffer() method in Java
- IntBuffer wrap() method in Java
- DoubleBuffer wrap() method in Java
- CharBuffer wrap() method in Java

Advertisements