Java IO Tutorial - Java FloatBuffer.compact()








Syntax

FloatBuffer.compact() has the following syntax.

public abstract FloatBuffer compact()

Example

In the following code shows how to use FloatBuffer.compact() method.

/*from  w w  w  .  ja  v a 2  s .  co  m*/
import java.nio.FloatBuffer;

public class Main {
  public static void main(String[] args) {
    FloatBuffer floatBuffer = FloatBuffer.allocate(10);
    
    floatBuffer.put(0,1.23F);
    
    floatBuffer.rewind();
    
    FloatBuffer floatBuffer1 = floatBuffer.compact();
    
    System.out.println(floatBuffer.equals(floatBuffer1));

  }
}

The code above generates the following result.