FloatBuffer hasArray() method in Java with Examples Last Updated : 06 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The hasArray() method of java.nio.FloatBuffer class is used to ensure whether or not the given buffer is backed by an accessible float array. It returns true if there is an accessible backing array to this buffer, else it returns false. If this method returns true, then the array() and arrayOffset() methods may safely be invoked, as they work on the backing array. Syntax : public final boolean hasArray() Returns: This method will return true if, and only if, this buffer is backed by an array and is not read-only. Else it returns false. Below are the examples to illustrate the hasArray() method: Examples 1: When the buffer is backed by an array Java // Java program to demonstrate // hasArray() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the capacity of the FloatBuffer int capacity = 10; // Creating the FloatBuffer try { // creating object of floatbuffer // and allocating size capacity FloatBuffer fb = FloatBuffer.allocate(capacity); // putting the value in floatbuffer fb.put(8.56F); fb.put(2, 9.61F); fb.rewind(); // checking FloatBuffer fb is backed by array or not boolean isArray = fb.hasArray(); // checking if else condition if (isArray) System.out.println("FloatBuffer fb is" + " backed by array"); else System.out.println("FloatBuffer fb is" + " not backed by any array"); } catch (IllegalArgumentException e) { System.out.println("IllegalArgumentException catched"); } catch (ReadOnlyBufferException e) { System.out.println("ReadOnlyBufferException catched"); } } } Output: FloatBuffer fb is backed by array Examples 2: When the buffer is backed by an array Java // Java program to demonstrate // hasArray() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the capacity of the FloatBuffer int capacity = 10; // Creating the FloatBuffer try { // creating object of floatbuffer // and allocating size capacity FloatBuffer fb = FloatBuffer.allocate(capacity); // putting the value in floatbuffer fb.put(8.56F); fb.put(2, 9.61F); fb.rewind(); // Creating a read-only copy of FloatBuffer // using asReadOnlyBuffer() method FloatBuffer fb1 = fb.asReadOnlyBuffer(); // checking FloatBuffer fb is backed by array or not boolean isArray = fb1.hasArray(); // checking if else condition if (isArray) System.out.println("FloatBuffer fb is" + " backed by array"); else System.out.println("FloatBuffer fb is" + " not backed by any array"); } catch (IllegalArgumentException e) { System.out.println("IllegalArgumentException catched"); } catch (ReadOnlyBufferException e) { System.out.println("ReadOnlyBufferException catched"); } } } Output: FloatBuffer fb is not backed by any array Comment More infoAdvertise with us Next Article FloatBuffer slice() method in Java with Examples R rohitprasad3 Follow Improve Article Tags : Misc Java Java-Functions Java-FloatBuffer Java-NIO package +1 More Practice Tags : JavaMisc Similar Reads FloatBuffer get() methods in Java with Examples get() The get() method of java.nio.FloatBuffer Class is used to reads the float at the given buffer's current position, and then increments the position. Syntax : public abstract float get() Return Value: This method returns the float value at the buffer's current position. Throws: This method throw 5 min read FloatBuffer wrap() method in Java with Examples wrap(float[] array) The wrap() method of java.nio.FloatBuffer Class is used to wraps a float array into a buffer. The new buffer will be backed by the given float array; that is, modifications to the buffer will cause the array to be modified and vice versa. The new buffer's capacity and limit will 4 min read FloatBuffer put() methods in Java with Examples put(float f) The put(float f) method of java.nio.FloatBuffer Class is used to write the given float into the newly created float buffer at the current position, and then increments the position. Syntax : public abstract FloatBuffer put(float f) Parameters: This method takes the float value f as a pa 6 min read FloatBuffer flip() methods in Java with Examples The flip() method of java.nio.FloatBuffer Class is used to flip this buffer. By flipping this buffer, it meant that the buffer will be trimmed to the current position and then the position will be changed to zero. During this process, if any mark is there on the buffer, then that mark will be automa 2 min read FloatBuffer slice() method in Java with Examples The slice() method of java.nio.FloatBuffer Class is used to creates a new float buffer whose content is a shared subsequence of the given buffer's content.The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, a 3 min read FloatBuffer equals() method in Java with Examples The equals() method of java.nio.FloatBuffer Class is used to check whether or not the given buffer is equal to another object. Two float buffers are equal if, and only if, They have the same element type, They have the same number of remaining elements, and The two sequences of remaining elements, c 4 min read Like