How to get specific index value from short buffer.


 

How to get specific index value from short buffer.

In this tutorial, you will see how to get specific index value from short buffer.

In this tutorial, you will see how to get specific index value from short buffer.

How to get specific index value from short buffer.

In this tutorial, we will discuss how  to get specific index value from short buffer.

ShortBuffer API:

The java.nio.ShortBuffer class extends java.nio.Buffer class. It provides the following methods:

Return type Method Description
static ShortBuffer allocate( int capacity)  The allocate(..) method allocate a short buffer of given capacity. 
abstract short get( int index) The get() method reads is short value at given index from short buffer.

Code

import java.nio.*;
import java.nio.ShortBuffer;
public class GetIndexValue {
public static final int index = 2;
public static void main(String[] arg) {
ShortBuffer shortBuff = ShortBuffer.allocate(1024);
    shortBuff.put((short787);
    shortBuff.put((short6432);
    shortBuff.put((short2775);
    shortBuff.put((short7653);
    shortBuff.flip();
    System.out.println("Value at index "+ index + 
     " in short buffer : "
+ shortBuff.get(index));
  }
}

Output

C:\>java GetIndexValue
Value at index 2 in short buffer : 2775

Download this code

Ads