IntBuffer flip() in Java

flip(): This method is available in java.nio.IntBuffer class of Java.

Syntax:

IntBuffer java.nio.IntBuffer.flip()

This method flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.

Parameters: NA

Returns: This buffer.

Exceptions: NA

Approach

Java

import java.nio.IntBuffer;

public class IntBufferflip {
    public static void main(String[] args) {

        int array[] = { 1, 2, 3, 4 };
        IntBuffer lb = IntBuffer.wrap(array);

        System.out.println(lb.flip());
    }
}

Output:

java.nio.HeapIntBuffer[pos=0 lim=0 cap=4]


IntBuffer equals(Object) in Java

equals(Object): This method is available in java.nio.IntBuffer class of Java.

Syntax:

boolean java.nio.IntBuffer.equals(Object ob)

This method takes one argument of type Object as its parameter. This method tells whether or not this buffer is equal to another object.

Note: A int buffer is not equal to any other type of object.

Parameters: One parameter is required for this method.

ob: The object to which this buffer is to be compared.

Returns: true if, and only if, this buffer is equal to the given object.

Exceptions: NA

Approach

Java

import java.nio.IntBuffer;

public class IntBufferequals {
    public static void main(String[] args) {

        int array[] = { 1, 2, 3, 4 };
        IntBuffer lb = IntBuffer.wrap(array);

        Object ob = IntBuffer.wrap(array);
        System.out.println(lb.equals(ob));
    }
}

Output:

true


IntBuffer duplicate() in Java

duplicate(): This method is available in java.nio.IntBuffer class of Java.

Syntax:

IntBuffer java.nio.IntBuffer.duplicate()

This method creates a new int buffer that shares this buffer's content.

Parameters: NA

Returns: The new int buffer.

Exceptions: NA

Approach

Java

import java.nio.IntBuffer;

public class IntBufferduplicate {
    public static void main(String[] args) {

        int array[] = { 1, 2, 3, 4 };
        IntBuffer lb = IntBuffer.wrap(array);

        System.out.println(lb.duplicate());
    }
}

Output:

java.nio.HeapIntBuffer[pos=0 lim=4 cap=4]


IntBuffer compareTo(IntBuffer) in Java

compareTo(IntBuffer): This method is available in java.nio.IntBuffer class of Java.

Syntax:

int java.nio.IntBuffer.compareTo(IntBuffer that)

This method takes one argument of type IntBuffer as its parameter. This method compares this buffer to another.

Two int buffers are compared by comparing their sequences of remaining elements lexicographically.

Parameters: One parameter is required for this method.

that: the object to be compared.

Returns: A negative integer, zero, or a positive integer as this buffer is less than, equal to, or greater than the given buffer.

Exceptions: NA

Approach

Java

import java.nio.IntBuffer;

public class IntBuffercompareTo {
    public static void main(String[] args) {

        int array[] = { 1, 2, 3, 4 };
        IntBuffer lb = IntBuffer.wrap(array);

        int array2[] = { 1, 2, 4, 6 };
        IntBuffer that = IntBuffer.wrap(array2);
        System.out.println(lb.compareTo(that));
    }
}

Output:

-1