This post show you how to use the java.nio
buffer such as ByteBuffer
, CharBuffer
, DoubleBuffer
, etc. To create a buffer you can use the allocate(int capacity)
method. Each buffer object has the allocate(int capacity)
method. You need to pass the value of the capacity of the buffer to be created when calling this method.
package org.kodejava.io;
import java.nio.*;
public class BufferAllocate {
public static void main(String[] args) {
ByteBuffer byteBuffer = ByteBuffer.allocate(64);
CharBuffer charBuffer = CharBuffer.allocate(64);
ShortBuffer shortBuffer = ShortBuffer.allocate(64);
IntBuffer intBuffer = IntBuffer.allocate(64);
LongBuffer longBuffer = LongBuffer.allocate(64);
FloatBuffer floatBuffer = FloatBuffer.allocate(64);
DoubleBuffer doubleBuffer = DoubleBuffer.allocate(64);
}
}
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024