nio入门一(Buffer类的使用)

1. Buffer类的说明

nio入门一(Buffer类的使用)

2. Buffer类的API

nio入门一(Buffer类的使用)

3. Buffer类的API使用,介绍子类ByteBuffer

1.创建对象和capacity的概念

ByteBuffer byteBuffer3 = ByteBuffer.wrap(new byte[] { 1, 2, 3, 4, 5 });
System.out.println(byteBuffer3);

输出结果如下:

java.nio.HeapByteBuffer[pos=0 lim=5 cap=5]

查看源码如下:
nio入门一(Buffer类的使用)
capacity的解释
A buffer’s capacity is the number of elements it contains. The capacity of a buffer is never negative and never changes.