CharBuffer: wrap(char[] array, int offset, int length) : CharBuffer « java.nio « Java by API






CharBuffer: wrap(char[] array, int offset, int length)

 

import java.nio.CharBuffer;

public class Main {
  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());
  }
}

   
  








Related examples in the same category

1.CharBuffer: allocate(int capacity)
2.CharBuffer: array()
3.CharBuffer: arrayOffset()
4.CharBuffer: capacity()
5.CharBuffer: flip()
6.CharBuffer: get()
7.CharBuffer: hasArray()
8.CharBuffer: hasRemaining()
9.CharBuffer: limit()
10.CharBuffer: limit(int newLimit)
11.CharBuffer: position()
12.CharBuffer: put(char c)
13.CharBuffer: put(String str)
14.CharBuffer: slice()
15.CharBuffer: subSequence(int start, int end)
16.CharBuffer: wrap(CharSequence csq)