Home Tutorial Java Corejava Checkforelement Check for any elements exists between the current position and the limit of a buffer.

 
 

Check for any elements exists between the current position and the limit of a buffer.
Posted on: July 27, 2010 at 12:00 AM
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 any 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 hasRemaining method returns true when there exists atleast one element in the buffer and returns false when there is no element available in the 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.hasRemaining());
    char[] chr1 = new char[] { 'a' };
    CharBuffer charbuffer2 = CharBuffer.wrap(chr1);
    charbuffer2.put(chr);
    System.out.println(charbuffer2.hasRemaining());
  }
}

Output:

 False
 True

Download this code

Advertisement

Related Tags for Check for any elements exists between the current position and the limit of a buffer.:


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.

Posted on: July 27, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com