import java.nio.CharBuffer; /** * Test the effects of buffer flipping. * */ public class MainClass { public static void main(String[] argv) throws Exception { CharBuffer cb = CharBuffer.allocate(15); cb.put("Hello World"); println(cb); cb.flip(); println(cb); cb.flip(); println(cb); } private static void println(CharBuffer cb) { System.out.println("pos=" + cb.position() + ", limit=" + cb.limit() + ": '" + cb + "'"); } }