FloatBuffer limit() Method in Java with Examples Last Updated : 10 Sep, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The limit() method of java.nio.FloatBuffer Class is used to modify this FloatBuffer's limit. This method takes the limit to be set as the parameter and sets that as the new limit of this Buffer. If the mark of this Buffer is already defined and is larger than the new specified limit, then this new limit is not set and discarded. Syntax: public final FloatBuffer limit(int newLimit) Parameter: The method takes one parameter newLimit of integer type which refers to the limit that is to be set as the new limit of the buffer. Return Value: The method returns this buffer after setting the specified new limit as the new limit of this Buffer. Below examples illustrate the limit() method: Examples 1: Java // Java program to demonstrate // limit() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // defining and allocating FloatBuffer // using allocate() method FloatBuffer floatBuffer = FloatBuffer.allocate(4); // put float value in FloatBuffer // using put() method floatBuffer.put(20.5f); floatBuffer.put(30.5f); // print the float buffer System.out.println( "FloatBuffer before " + "setting buffer's limit: " + Arrays.toString( floatBuffer.array()) + "\nPosition: " + floatBuffer.position() + "\nLimit: " + floatBuffer.limit()); // Limit the floatBuffer // using limit() method floatBuffer.limit(1); // print the float buffer System.out.println( "\nFloatBuffer after " + "setting buffer's limit: " + Arrays.toString( floatBuffer.array()) + "\nPosition: " + floatBuffer.position() + "\nLimit: " + floatBuffer.limit()); } } Output: FloatBuffer before setting buffer's limit: [20.5, 30.5, 0.0, 0.0] Position: 2 Limit: 4 FloatBuffer after setting buffer's limit: [20.5, 30.5, 0.0, 0.0] Position: 1 Limit: 1 Examples 2: Java // Java program to demonstrate // limit() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // defining and allocating FloatBuffer // using allocate() method FloatBuffer floatBuffer = FloatBuffer.allocate(5); // put float value in FloatBuffer // using put() method floatBuffer.put(20.5f); floatBuffer.put(30.5f); floatBuffer.put(40.5f); // mark will be going to // discarded by limit() floatBuffer.mark(); // print the float buffer System.out.println( "FloatBuffer before " + "setting buffer's limit: " + Arrays.toString( floatBuffer.array()) + "\nPosition: " + floatBuffer.position() + "\nLimit: " + floatBuffer.limit()); // Limit the floatBuffer // using limit() method floatBuffer.limit(4); // print the double buffer System.out.println( "\nFloatBuffer before " + "setting buffer's limit: " + Arrays.toString( floatBuffer.array()) + "\nPosition: " + floatBuffer.position() + "\nLimit: " + floatBuffer.limit()); } } Output: FloatBuffer before setting buffer's limit: [20.5, 30.5, 40.5, 0.0, 0.0] Position: 3 Limit: 5 FloatBuffer before setting buffer's limit: [20.5, 30.5, 40.5, 0.0, 0.0] Position: 3 Limit: 4 Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/FloatBuffer.html#limit-int- Comment More infoAdvertise with us Next Article FloatBuffer wrap() method 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 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 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