Home Tutorial Java Corejava Nio Get the limit position and capacity of a character buffer.

 
 

Get the limit position and capacity of a character buffer.
Posted on: July 27, 2010 at 12:00 AM
In this tutorial you will see how to get the limit position and capacity of a character buffer.

Get the limit position and capacity of a character buffer.

In this tutorial you will see how to get the limit position and capacity of a character buffer. The given example illustrate the use of limit() method which returns the buffer's limit like wise capacity() and   position() methods return capacity and position..

Code:

import java.nio.CharBuffer;

public class CharBufferDemo1 {
  public static void main(String[] args) {
    char[] str = new char[] { 'a''b''c''d''e' };
    CharBuffer charbuffer1 = CharBuffer.wrap(str);
    charbuffer1.rewind();
    CharBuffer charbuffer2 = charbuffer1.asReadOnlyBuffer();
    System.out.printf("position = %d  Limit = %d  capacity = %d%n",
        charbuffer2.position(), charbuffer2.limit(), charbuffer2
            .capacity());
  }
}

Output:

   position = 0 Limit = 5 capacity = 5

Download this code

Related Tags for Get the limit position and capacity of a character buffer.:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.