MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

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());
    }
}
/*
*/