LongBuffer class in java

java.nio.LongBuffer is a class in java programming language. Inside of this class exists 25 public methods. Declaration of this class as follows.

public abstract class java.nio.LongBuffer 
extends java.nio.Buffer 
implements java.lang.Comparable <java.nio.LongBuffer > 

LongBuffer public method

There are following useful methods which is define the inside of java.nio.LongBuffer class.

MethodDescription
static LongBuffer allocate(int capacity) It allocates a new long buffer.
long[] array() It returns the long array that backs this buffer (optional operation).
int arrayOffset() It returns the offset within this buffer's backing array of the first element of the buffer (optional operation).
abstract LongBuffer asReadOnlyBuffer() It creates a new, read-only long buffer that shares this buffer's content.
abstract LongBuffer compact() It compacts this buffer (optional operation).
int compareTo(LongBuffer that) It compares this buffer to another.
abstract LongBuffer duplicate() It creates a new long buffer that shares this buffer's content.
boolean equals(Object ob) It tells whether or not this buffer is equal to another object.
abstract long get() It relative get method.
abstract long get(int index) It absolute get method.
LongBuffer get(long[] dst) It relative bulk get method.
LongBuffer get(long[] dst, int offset, int length) It relative bulk get method.
boolean hasArray() It tells whether or not this buffer is backed by an accessible long array.
int hashCode() It returns the current hash code of this buffer.
abstract boolean isDirect() It tells whether or not this long buffer is direct.
abstract ByteOrder order() It retrieves this buffer's byte order.
abstract LongBuffer put(int index, long l) It absolute put method (optional operation).
abstract LongBuffer put(long l) It relative put method (optional operation).
LongBuffer put(long[] src) It relative bulk put method (optional operation).
LongBuffer put(long[] src, int offset, int length) It relative bulk put method (optional operation).
LongBuffer put(LongBuffer src) It relative bulk put method (optional operation).
abstract LongBuffer slice() It creates a new long buffer whose content is a shared subsequence of this buffer's content.
String toString() It returns a string summarizing the state of this buffer.
static LongBuffer wrap(long[] array) It wraps a long array into a buffer.
static LongBuffer wrap(long[] array, int offset, int length) It wraps a long array into a buffer.

This reference is belong to javadoc

java.nio.LongBuffer allocate(int) method example

// allocate(int) method in java.nio.LongBuffer class 
import java.nio.LongBuffer;
public class Example
{
    public static void main(String[] args)
    {
        try
        {
            LongBuffer buffer = LongBuffer.allocate(5);
            // Put long value
            buffer.put(12L);
            buffer.put(20L);
            buffer.put(30L);
            buffer.put(40L);
            buffer.put(30L);
            buffer.rewind();
           
            System.out.println(buffer);
        }
        catch (Exception e)
        {
            System.out.println(e);
        }
    }
}
LongBuffer example
java.nio.HeapLongBuffer[pos=0 lim=5 cap=5]

java.nio.LongBuffer array() method example

This method are returns the reference of array.

// array() method in java.nio.LongBuffer class 
// Useful packages
import java.nio.LongBuffer;
public class Example
{
    public static void main(String[] args)
    {
        try
        {
            LongBuffer buffer = LongBuffer.allocate(5);
            // Put long value
            buffer.put(10L);
            buffer.put(20L);
            buffer.put(30L);
            buffer.put(40L);
            buffer.put(30L);
            buffer.rewind();
           
            // Get short array
            long[] result = buffer.array();

            for (long value: result)
            {
                System.out.println(value);
            }
        }
        catch (Exception e)
        {
            System.out.println(e);
        }
    }
}
LongBuffer array method example
10
20
30
40
30

Other methods are coming soon.



Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved