FloatBuffer rewind() methods in Java with ExamplesThe java.nio.FloatBuffer Class's rewind() function is used to clear this buffer. This buffer is returned using the FloatBuffer Class. With this procedure, the position is reset to zero, the limit is unchanged, and all previously designated positions are removed. When a series of channel write or get operations is required, this procedure ought to be called. It indicates that data from the buffer has to be duplicated into another array if it has already been written. Syntax: Parameters: There are no parameters required by the method. Return Value: This buffer is returned by the method. Example 1:The Java code shows how to use a FloatBuffer. A FloatBuffer with a capacity of five elements is first allocated. The put() method is then used to add two float values (11.5f and 22.5f) to the buffer. The code prints the contents, location, and limit of the buffer both before and after invoking the rewind() method. The rewind() function allows the buffer to be read or written from the beginning again by resetting its position to zero without altering the limit. Reprocessing the data in the buffer can benefit from this. Implementation:FileName: rewindFloatExample1.java Output: The Buffer before operation is : [11.5, 22.5, 0.0, 0.0, 0.0] The Position: 2 The Limit: 5 The Buffer before operation is : [11.5, 22.5, 0.0, 0.0, 0.0] The Position: 0 The Limit: 5 Example 2:The code that is provided shows how to utilize FloatBuffer in Java. It assigns a seven-capacity FloatBuffer and uses the put function to enter three float values. The buffer's current position is then indicated. It prints the buffer's contents, position, and limit before rewinding. The mark is discarded and the buffer's location is reset to zero via the rewind procedure. In order to demonstrate the impact of the rewind operation, it outputs the buffer's contents, position, and limit one last time. This demonstrates how rewind sets up the buffer such that it can read the data again from the start. Implementation:FileName: rewindFloatExample2.java Output: The Buffer before operation is given by : [11.1, 22.2, 33.3, 0.0, 0.0, 0.0, 0.0] The Position is: 3 The Limit is: 7 The Buffer after operation is given by : [11.1, 22.2, 33.3, 0.0, 0.0, 0.0, 0.0] The Position is: 0 The Limit is: 7 |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India