FloatBuffer mark() methods in Java with Examples Last Updated : 10 Sep, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The mark() method of java.nio.FloatBuffer Class is used to mark the current position of this FloatBuffer as the mark of this buffer. Syntax: public final FloatBuffer mark() Parameters: The method does not take any parameters. Return Value: This method returns this FloatBuffer after setting the buffer's mark at the current position. Below examples illustrate the mark() method: Examples 1: Java // Java program to demonstrate // mark() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { try { float[] farr = { 10.5f, 20.5f, 30.5f, 40.5f }; // creating object of FloatBuffer // and allocating size capacity FloatBuffer fb = FloatBuffer.wrap(farr); // try to set the position at index 2 fb.position(2); // Set this buffer mark position // using mark() method fb.mark(); // try to set the position at index 4 fb.position(4); // display position System.out.println("position before reset: " + fb.position()); // try to call reset() to restore // to the position we marked fb.reset(); // display position System.out.println("position after reset: " + fb.position()); } catch (InvalidMarkException e) { System.out.println("New position " + "is less than " + "the position " + "marked before "); System.out.println("Exception throws: " + e); } } } Output: position before reset: 4 position after reset: 2 Examples 2: To demonstrate InvalidMarkException Java // Java program to demonstrate // mark() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { try { float[] farr = { 10.5f, 20.5f, 30.5f, 40.5f }; // creating object of FloatBuffer // and allocating size capacity FloatBuffer fb = FloatBuffer.wrap(farr); // try to set the position at index 2 fb.position(2); // Set this buffer mark position // using mark() method fb.mark(); // try to set the position at index 1 fb.position(1); // display position System.out.println("position before reset: " + fb.position()); // try to call reset() to restore // to the position we marked fb.reset(); // display position System.out.println("position after reset: " + fb.position()); } catch (InvalidMarkException e) { System.out.println("\nNew position " + "is less than " + "the position " + "marked before "); System.out.println("Exception throws: " + e); } } } Output: position before reset: 1 New position is less than the position marked before Exception throws: java.nio.InvalidMarkException Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/FloatBuffer.html#mark-- Comment More infoAdvertise with us Next Article FloatBuffer put() methods in Java with Examples R rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-FloatBuffer Java-NIO package Practice Tags : Java 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 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 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 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