Example usage for java.nio CharBuffer compact

List of usage examples for java.nio CharBuffer compact

Introduction

In this page you can find the example usage for java.nio CharBuffer compact.

Prototype

public abstract CharBuffer compact();

Source Link

Document

Compacts this char buffer.

Usage

From source file:Main.java

public static void main(String[] args) {
    CharBuffer cb1 = CharBuffer.allocate(50);
    cb1.append("java2s.com");
    cb1.rewind();//from w w w. j  ava 2s .c  o  m

    System.out.println(cb1.charAt(2));
    System.out.println(Arrays.toString(cb1.array()));

    CharBuffer cb2 = cb1.compact();
    System.out.println(Arrays.toString(cb2.array()));

}