当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java ShortBuffer isDirect()用法及代码示例


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–



相关用法


注:本文由纯净天空筛选整理自IshwarGupta大神的英文原创作品 ShortBuffer isDirect() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。