import java.nio.CharBuffer;
public class test_01 {
public static void main(String[] args) {
//CharBuffer类的API
//1:append的三个方法
mehtod_01();
private static void mehtod_01(){
/*
* 1:append(char)
* 2:append(charArray)
* 3:append(charArray,start,end)
* */
CharBuffer charBuffer = CharBuffer.allocate(10);
charBuffer.append('a');
char[] chars = charBuffer.array();
for (int i = 0; i < chars.length; i++) {
System.out.print(chars[i]+" ");
}
System.out.println();
charBuffer.append("bcdef");
chars = charBuffer.array();
for (int i = 0; i < chars.length; i++) {
System.out.print(chars[i]+" ");
}
//从“ghijflmn”的0开始到3结束,截取4位
charBuffer.append("ghijflmn",0,3);
System.out.println();
chars = charBuffer.array();
for (int i = 0; i < chars.length; i++) {
System.out.print(chars[i]+" ");
}
}
//2:获取缓冲区的长度
method_02();
private static void method_02(){
/*源码:
public final int length() {
return remaining();
}
*
* */
CharBuffer charBuffer = CharBuffer.allocate(10);
System.out.println(charBuffer.length());
}
}
}