java.nio.ByteBuffer類的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)
{
// defining and allocating ByteBuffer
// using allocate() method
ByteBuffer byteBuffer
= ByteBuffer.allocateDirect(4);
// check the byteBuffer
// using isDirect() method
boolean val = byteBuffer.isDirect();
// checking the condition
if (val)
System.out.println("buffer is direct");
else
System.out.println("buffer is not direct");
}
}
輸出:
buffer is direct
範例2:
// Java program to demonstrate
// isDirect() method
import java.nio.*;
import java.util.*;
public class GFG {
public static void main(String[] args)
{
// defining and allocating ByteBuffer
// using allocate() method
ByteBuffer byteBuffer = ByteBuffer.allocate(4);
// check the byteBuffer
// using isDirect() method
boolean val = byteBuffer.isDirect();
// checking the condition
if (val)
System.out.println("buffer is direct");
else
System.out.println("buffer is not direct");
}
}
輸出:
buffer is not direct
參考:https://docs.oracle.com/javase/9/docs/api/java/nio/ByteBuffer.html#isDirect-
相關用法
- Java Buffer isDirect()用法及代碼示例
- Java ByteBuffer put()方法用法及代碼示例
- Java ByteBuffer flip()用法及代碼示例
- Java ByteBuffer putInt()用法及代碼示例
- Java ByteBuffer clear()用法及代碼示例
- Java ByteBuffer limit()用法及代碼示例
- Java ByteBuffer putDouble()用法及代碼示例
- Java ByteBuffer putChar()用法及代碼示例
- Java ByteBuffer wrap()用法及代碼示例
- Java ByteBuffer putFloat()用法及代碼示例
- Java ByteBuffer putLong()用法及代碼示例
- Java ByteBuffer reset()用法及代碼示例
- Java ByteBuffer rewind()用法及代碼示例
- Java ByteBuffer position()用法及代碼示例
- Java ByteBuffer mark()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 ByteBuffer isDirect() methods in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。