ByteBuffer

阅读更多

 

 

ByteBuffer:

创建ByteBuffer的两种方式:

ByteBuffer buffer = ByteBuffer.wrap(byte[]);

ByteBuffer buffer = ByteBuffer.allocate(int );

capacity:buffer的容量

limit:可读写的范围 如果容量是10 ,limit是5,则只有前5位是可读写的

position:当前位置,也就是下一次读或写的位置

 

filip:将limit置为当前文职,将position置为0

rewind:将position置为0

clear:并不会清空数据,将position置为0 , 将limit置为capacity

remaining:返回当前位置与限制之间的元素数

hasremainint:返回当前位置与限制之间是否有元素

 

get , put都会使position往后走一位,并不会删除元素

你可能感兴趣的:(ByteBuffer,java)