本文共 1167 字,大约阅读时间需要 3 分钟。
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://blog.csdn.net/weixin_32804237/article/details/114186578 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!