Sunday 9 June 2019

Nio: Get the buffer capacity

Buffer class provides ‘capacity’ method that returns the total number of elements that a buffer can accommodate.

Find the below working application.

Test.java
package com.sample.nio;

import java.nio.Buffer;
import java.nio.ByteBuffer;

public class Test {

 public static void main(String args[]) throws Exception {
  Buffer byteBuffer = ByteBuffer.allocate(10);
  
  System.out.println("Capacity of the buffer : " + byteBuffer.capacity());
 }
}


Output
Capacity of the buffer : 10

Previous                                                 Next                                                 Home

No comments:

Post a Comment