compact(): This method is available in java.nio.LongBuffer class of Java.
Syntax:
LongBuffer java.nio.LongBuffer.compact()
Compacts this buffer.
Note The longs between the buffer's current position and its limit, if any, are copied to the beginning of the buffer.
Parameters: NA
Returns: This buffer.
Throws:
ReadOnlyBufferException - If this buffer is read-only
Approach
Java
import java.nio.LongBuffer;public class LongBuffercompact {public static void main(String[] args) {long array[] = { 1, 2, 3, 4 };LongBuffer lb = LongBuffer.wrap(array);System.out.println(lb.compact());}}
Output:
java.nio.HeapLongBuffer[pos=4 lim=4 cap=4]
No comments:
Post a Comment