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 build simple search page using ZK and Spring Boot? - March 8, 2023
- How do I calculate days between two dates excluding weekends and holidays? - January 12, 2023
- How do I discover the quarter of a given date? - January 11, 2023