Java ShortBuffer .asReadOnlyBuffer ()

Syntax

ShortBuffer.asReadOnlyBuffer() has the following syntax.

public abstract ShortBuffer asReadOnlyBuffer()

Example

In the following code shows how to use ShortBuffer.asReadOnlyBuffer() method.


import java.nio.ShortBuffer;
import java.util.Arrays;
//from w ww .j  a va 2 s . c  o  m
public class Main {
  public static void main(String[] args) {
    ShortBuffer shortBuffer = ShortBuffer.allocate(10);
    shortBuffer.put((short)100);
    
    shortBuffer.rewind();
    
    
    ShortBuffer shortBuffer2 = shortBuffer.asReadOnlyBuffer();
    
    System.out.println(Arrays.toString(shortBuffer2.array()));

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.nio »




Buffer
ByteBuffer
ByteOrder
CharBuffer
DoubleBuffer
FloatBuffer
IntBuffer
LongBuffer
MappedByteBuffer
ShortBuffer