當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。