The clear() method of java.nio.FloatBuffer Class is used to clear this buffer. This method set the position and limit equal to zero and capacity respectively and discard the mark. This method should be invoked when there is any necessity of sequence of channel-read or put operations. It means that if the buffer needs to be read then clear() method makes the buffer ready and set the position to zero. For example:
buf.clear(); // Prepare buffer for reading in.read(buf); // Read data
The method does not actually erase the data in the buffer, but it is named as if it did because it will most often be used in situations in which deletion might as well be the case.
public final FloatBuffer clear()
Parameters: The method does not take any parameters.
Return Value: This method returns this FloatBuffer instance after clearing all the data from it.
Below are the examples to illustrate the clear() method:
position before reset: 4 position after reset: 0
position before clear: 3 position after clear: 0
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.