java.nio.ShortBuffer的isDirect()方法用於檢查此短緩衝區是否為直接緩衝區。
用法:
public abstract boolean isDirect()
返回值:當且僅當此緩衝區為直接緩衝區時,該方法返回true
以下示例程序旨在說明isDirect()方法的使用:
程序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.");
}
}
}
輸出:
Short buffer is not direct.
程序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.");
}
}
}
輸出:
Short buffer is direct.
參考: https://docs.oracle.com/javase/9/docs/api/java/nio/ShortBuffer.html#isDirect–
相關用法
- Java ShortBuffer asReadOnlyBuffer()用法及代碼示例
- Java ShortBuffer limit()用法及代碼示例
- Java ShortBuffer arrayOffset()用法及代碼示例
- Java ShortBuffer allocate()用法及代碼示例
- Java ShortBuffer reset()用法及代碼示例
- Java ShortBuffer compareTo用法及代碼示例
- Java ShortBuffer mark()用法及代碼示例
- Java ShortBuffer rewind()用法及代碼示例
- Java ShortBuffer duplicate()用法及代碼示例
- Java ShortBuffer equals()用法及代碼示例
- Java ShortBuffer hasArray()用法及代碼示例
- Java ShortBuffer array()用法及代碼示例
- Java ShortBuffer hashCode()用法及代碼示例
- Java ShortBuffer toString()用法及代碼示例
- Java ShortBuffer order()用法及代碼示例
注:本文由純淨天空篩選整理自IshwarGupta大神的英文原創作品 ShortBuffer isDirect() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。