ShortBuffer isDirect() Method in Java with Examples
Last Updated :
17 Jun, 2019
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:
import java.nio.*;
import java.util.*;
public class GFG {
public static void main(String[] args)
{
short [] array = { 10000 , 10640 , 10189 , - 2000 , - 16780 };
ShortBuffer shortBuf1 = ShortBuffer.wrap(array);
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:
import java.nio.*;
import java.util.*;
public class GFG {
public static void main(String[] args)
{
ByteBuffer b = ByteBuffer.allocateDirect( 512 );
ShortBuffer shortBuf = b.asShortBuffer();
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–
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...