本文整理匯總了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) {}
}