Saturday, November 22, 2025
HomeLanguagesJavaShortBuffer isDirect() Method in Java with Examples

ShortBuffer isDirect() Method in Java with Examples

The isDirect() method of java.nio.ShortBuffer is used to check whether or not this short buffer is direct.

Syntax:

public abstract boolean isDirect()

Return Value: The method returns true if and only if, this buffer is direct

Below programs illustrate the use of isDirect() method:

Program 1:




// Java program to demonstrate
// isDirect() method
  
import java.nio.*;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        short[] array = { 10000, 10640, 10189, -2000, -16780 };
  
        // creating short array
        ShortBuffer shortBuf1 = ShortBuffer.wrap(array);
  
        // checking if the array is Direct or not
        if (shortBuf1.isDirect()) {
            System.out.println("Short buffer is direct.");
        }
        else {
            System.out.println("Short buffer is not direct.");
        }
    }
}


Output:

Short buffer is not direct.

Program 2:




// Java program to demonstrate
// isDirect() method
  
import java.nio.*;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        ByteBuffer b = ByteBuffer.allocateDirect(512);
  
        ShortBuffer shortBuf = b.asShortBuffer();
  
        // checking if the array is Direct or not
        if (shortBuf.isDirect()) {
            System.out.println("Short buffer is direct.");
        }
        else {
            System.out.println("Short buffer is not direct.");
        }
    }
}


Output:

Short buffer is direct.

Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/ShortBuffer.html#isDirect–

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6864 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS