本文整理汇总了Java中java.util.ArrayDeque.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayDeque.toArray方法的具体用法?Java ArrayDeque.toArray怎么用?Java ArrayDeque.toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.ArrayDeque
的用法示例。
在下文中一共展示了ArrayDeque.toArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: search
import java.util.ArrayDeque; //导入方法依赖的package包/类
public static int search(byte[] target, byte[] input) {
Object[] targetB = new Byte[target.length];
int x = 0;
while (x < target.length) {
targetB[x] = target[x];
++x;
}
int idx = -1;
ArrayDeque<Byte> q = new ArrayDeque<Byte>(input.length);
int i = 0;
while (i < input.length) {
if (q.size() == targetB.length) {
Object[] cur = q.toArray(new Byte[0]);
if (Arrays.equals(cur, targetB)) {
idx = i - targetB.length;
break;
}
q.pop();
q.addLast(input[i]);
} else {
q.addLast(input[i]);
}
++i;
}
return idx;
}
示例2: arrayDequeStuff
import java.util.ArrayDeque; //导入方法依赖的package包/类
static void arrayDequeStuff() {
ArrayDeque<Object> d = new ArrayDeque<>();
// BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
d.add(null);
// BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
d.addFirst(null);
// BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
d.addLast(null);
// BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
d.offerFirst(null);
// BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
d.offerLast(null);
// BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
d.offer(null);
// BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
d.push(null);
// BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
d.toArray(null);
// this should be fine
d.toArray();
}
示例3: testToArray_NullArg
import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
* toArray(null) throws NullPointerException
*/
public void testToArray_NullArg() {
ArrayDeque l = new ArrayDeque();
l.add(new Object());
try {
l.toArray(null);
shouldThrow();
} catch (NullPointerException success) {}
}