Share on Google+Share on Google+

Check for number of elements exists between the current position and the limit of a buffer.

Advertisement
In this tutorial you will see how to check for existence of any element between the current position and the limit of a buffer.

Check for number of elements exists between the current position and the limit of a buffer.

In this tutorial you will see how to check for existence of any element between the current position and the limit of a buffer. The remaining method returns the number of element available in a buffer.

Code:

import java.nio.CharBuffer;

public class CharBufferDemo {
  public static void main(String[] args) {
    char[] chr = new char[] {};
    CharBuffer charbuffer1 = CharBuffer.wrap(chr);
    charbuffer1.put(chr);
    System.out.println(charbuffer1.remaining());
    char[] chr1 = new char[] { 'a' , 'b' };
    CharBuffer charbuffer2 = CharBuffer.wrap(chr1);
    charbuffer2.put(chr);
    System.out.println(charbuffer2.remaining());
  }
}

Output:

 0
 2

Download this code

Advertisements

Posted on: July 27, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.