ShortBuffer hasArray() 方法
使用 java.nio.ShortBuffer 类中的 hasArray() 方法可以检查缓冲区是否具有可访问的 short 数组的支持。如果缓冲区具有可访问的 double 数组的支持,此方法返回 true,否则返回 false。
一个演示此功能的程序如下 −
例子
import java.nio.*;
import java.util.*;
public class Demo {
public static void main(String[] args) {
int n = 5;
try {
ShortBuffer buffer = ShortBuffer.allocate(5);
buffer.put((short)12);
buffer.put((short)91);
buffer.put((short)25);
buffer.put((short)18);
buffer.put((short)30);
buffer.rewind();
System.out.println("The ShortBuffer is: " + Arrays.toString(buffer.array()));
boolean flag = buffer.hasArray();
if (flag)
System.out.println("The ShortBuffer is backed by an array");
else
System.out.println("The ShortBuffer is not backed by any array");
} catch (IllegalArgumentException e) {
System.out.println("Error!!! IllegalArgumentException");
} catch (ReadOnlyBufferException e) {
System.out.println("Error!!! ReadOnlyBufferException");
}
}
}输出
The ShortBuffer is: [12, 91, 25, 18, 30] The ShortBuffer is backed by an array
广告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP