Java IO Tutorial - Java LongBuffer.compact()








Syntax

LongBuffer.compact() has the following syntax.

public abstract LongBuffer compact()

Example

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

import java.nio.LongBuffer;
import java.util.Arrays;
/*  ww  w.ja  va 2  s .c om*/
public class Main {
  public static void main(String[] args) {
    LongBuffer longBuffer = LongBuffer.allocate(10);
    longBuffer.put(100);
    
    longBuffer.rewind();
    
    
    LongBuffer longBuffer2 = longBuffer.compact();
    
    System.out.println(Arrays.toString(longBuffer2.array()));

  }
}

The code above generates the following result.