import java.nio.CharBuffer;
public class MainClass {
public static void main(String[] argv) throws Exception {
char[] chars = new char[60];
CharBuffer cb = CharBuffer.wrap(chars, 12, 42);
println(cb);
cb.put("This is a test String");
cb.flip();
println(cb);
cb.clear();
cb.put("Foobar");
println(cb);
for (int i = 0; i < 20; i++) {
System.out.println("[" + i + "] = " + chars[i]);
}
}
private static void println(CharBuffer cb) {
System.out.println("pos=" + cb.position() + ", limit=" + cb.limit() + ", capacity="
+ cb.capacity() + ", arrayOffset=" + cb.arrayOffset());
}
}
/*
*/
|
|
pos=12, limit=54, capacity=60, arrayOffset=0
pos=0, limit=33, capacity=60, arrayOffset=0
pos=6, limit=60, capacity=60, arrayOffset=0
[0] = F
[1] = o
[2] = o
[3] = b
[4] = a
[5] = r
... |