Home Tutorial Java Corejava Nio ShortBuffer in java, Use of slice method of ShortBuffer class.

 
 

Share on Google+Share on Google+
ShortBuffer in java, Use of slice method of ShortBuffer class.
Posted on: August 13, 2010 at 12:00 AM
Advertisement
In this tutorial, you will see the use of slice method of ShortBuffer class.

ShortBuffer in java, Use of slice method of ShortBuffer class.

In this tutorial, we will see the use of slice method of ShortBuffer class in java.

ShortBuffer API:

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

Return type Method Description
static ShortBuffer wrap(short [] array)  The wrap(....) method wrapping an existing short array into short buffer.
abstract ShortBuffer slice() The slice() method returns slice buffer that share the remaining content of associated short buffer.

Code

import java.nio.*;
import java.nio.ShortBuffer;

public class SliceShortBuffer {
  public static void main(String[] arg) {
    short[] array = new short[] { 789734};
    ShortBuffer shortBuf = ShortBuffer.wrap(array);
    System.out.println("Elements in short buffer.");
    while (shortBuf.hasRemaining()) {
      System.out.print(shortBuf.get() " ");
    }
    shortBuf.flip();
    System.out.println();
  System.out.println("Remaining element in buffer : "
        + shortBuf.remaining());
    ShortBuffer shortBuf1 = shortBuf.slice();
System.out.println("Elements in slice short buffer.");
    while (shortBuf1.hasRemaining()) {
      System.out.print(shortBuf1.get() " ");
    }
  }
}

Output

C:\>java SliceShortBuffer
Elements in short buffer.
78 97 34 5
Remaining element in buffer : 4
Elements in slice short buffer.
78 97 34 5

Download this code

Advertisement

Related Tags for ShortBuffer in java, Use of slice method of ShortBuffer class.:


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 13, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com