import java.nio.CharBuffer;
public class MainClass {
public static void main(String[] argv) throws Exception {
CharBuffer buffer = CharBuffer.allocate(8);
buffer.position(3).limit(5);
CharBuffer sliceBuffer = buffer.slice();
println(buffer);
println(sliceBuffer);
char[] myBuffer = new char[100];
CharBuffer cb = CharBuffer.wrap(myBuffer);
cb.position(12).limit(21);
CharBuffer sliced = cb.slice();
println(cb);
println(sliced);
}
private static void println(CharBuffer cb) {
System.out.println("pos=" + cb.position() + ", limit=" + cb.limit() + ", capacity="
+ cb.capacity() + ", arrayOffset=" + cb.arrayOffset());
}
}
/*
*/
pos=3, limit=5, capacity=8, arrayOffset=0
pos=0, limit=2, capacity=2, arrayOffset=3
pos=12, limit=21, capacity=100, arrayOffset=0
pos=0, limit=9, capacity=9, arrayOffset=12