Java CharBuffer create from char array

Description

Java CharBuffer create from char array


import java.nio.CharBuffer;
import java.util.Arrays;

public class Main {
  public static void main(String[] argv) throws Exception {
    char[] charArray = new char[] { 'a', 'b', 'c', 'd', 'e' };
    CharBuffer bb = CharBuffer.wrap(charArray);

    charArray = toArray(bb);/*  w  w  w  .j a v  a  2 s .  c  om*/

    System.out.println(Arrays.toString(charArray));
  }

  public static char[] toArray(final CharBuffer buffer) {
    char[] array = new char[buffer.limit()];
    buffer.get(array);
    return array;
  }

}



PreviousNext

Related