Home Tutorial Java Corejava Nio How to get specific index value from short buffer.

 
 

How to get specific index value from short buffer.
Posted on: August 11, 2010 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for How to get specific index value from short 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: August 11, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com