Java Buffer.limit()

Syntax

Buffer.limit() has the following syntax.

public final int limit()

Example

In the following code shows how to use Buffer.limit() method.


import java.nio.ByteBuffer;
/*from w ww . j a va  2  s . c om*/
public class Main {
  private static final int BSIZE = 10;

  public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    int i = 0;
    while (i++ < bb.limit())
      if (bb.get() != 0) {
        System.out.println("nonzero");
      }

    System.out.println("i = " + i);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.nio »




Buffer
ByteBuffer
ByteOrder
CharBuffer
DoubleBuffer
FloatBuffer
IntBuffer
LongBuffer
MappedByteBuffer
ShortBuffer