Home Tutorial Java Corejava Nio ShortBuffer in java, Transfer the content of a short buffer into another.

 
 

Share on Google+Share on Google+
ShortBuffer in java, Transfer the content of a short buffer into another.
Posted on: August 13, 2010 at 12:00 AM
Advertisement
In this tutorial, you will see how to transfer the content of a short buffer into another.

ShortBuffer in java, Transfer the content of a short buffer into another.

 In this tutorial, we will see how to transfer the content of a short buffer into another 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 wrap(short [] array)  The wrap(....) method wrapping an existing short array into short buffer.
 ShortBuffer put(ShortBuffer buffer) The put(..)method transfer the content of a short buffer into another short buffer.

Code

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

public class BufferToBuffer {
  public static void main(String[] arg) {
    short[] array = new short[] { 789734};
    ShortBuffer shortBuf = ShortBuffer.wrap(array);
    ShortBuffer shortBuf1 = ShortBuffer.allocate(256);
    System.out.println("Transfer the content from one"
        " short buffer into another short buffer.");
  System.out.println("Elements in this short buffer.");
    while (shortBuf.hasRemaining()) {
      System.out.print(shortBuf.get() " ");
    }
    shortBuf.flip();
    shortBuf1.put(shortBuf);
    shortBuf1.flip();
    System.out.println();
System.out.println("Elements in another short buffer.");
    while (shortBuf1.hasRemaining()) {
      System.out.print(shortBuf1.get() " ");
    }
  }
}

Output

C:\>java BufferToBuffer
Transfer the content from one short buffer into another short buffer.
Elements in this short buffer.
75 33 442 23
Elements in another short buffer.
75 33 442 23

Download this code

Advertisement

Related Tags for ShortBuffer in java, Transfer the content of a short buffer into another.:


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