Write a long value at given index into long buffer.


 

Write a long value at given index into long buffer.

In this tutorial, you will see how to write a long value at given index into long buffer.

In this tutorial, you will see how to write a long value at given index into long buffer.

Write a long value at given index into long buffer.

 In this tutorial, we will see how to write a long value at given index into long buffer.

LongBuffer API:

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

Return type Method Description
static LongBuffer wrap(long[] array)  The wrap(....) method wrap an existing long array and create long buffer.
abstract  LongBuffer put(int index, long value) The put(..) method write the given long value into buffer at given index.
abstract long get() The get() method read long value from given index.

Code

import java.nio.*;
import java.nio.LongBuffer;

public class PutAtIndex {
p  final static int index = 1;
  public static void main(String[] args){
long[] array = new long[] { 446456695755477677557434 };
    LongBuffer longBuf = LongBuffer.wrap(array);
    System.out.println("Value in buffer.");
    for (int i = 0; i < longBuf.limit(); i++) {
      System.out.println(longBuf.get());
    }
    longBuf.put(112345);
    longBuf.flip();
System.out.print("After putting value at index : " + index);
    System.out.println(" Value in buffer.");
    for (int i = 0; i < longBuf.limit(); i++) {
      System.out.println(longBuf.get());
    }
  }
}

Output

C:\>java PutAtIndex
Value in buffer.
44645669
57554776
77557434
After putting value at index : 1 Value in buffer.
44645669
12345
77557434

Download this code

Ads