java directbuffer_Java ByteBuffer isDirect()用法及代码示例
发布日期:2021-06-24 12:40:58 浏览次数:2 分类:技术文章

本文共 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:java traits_使用traits增强java类,如何在java字段中声明内部特征?
下一篇:%02x java_java基础---->Java的格式化输出

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月07日 04时47分08秒