本文整理匯總了Java中java.util.ArrayDeque.offerLast方法的典型用法代碼示例。如果您正苦於以下問題:Java ArrayDeque.offerLast方法的具體用法?Java ArrayDeque.offerLast怎麽用?Java ArrayDeque.offerLast使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.ArrayDeque
的用法示例。
在下文中一共展示了ArrayDeque.offerLast方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: main
import java.util.ArrayDeque; //導入方法依賴的package包/類
public static void main(String[] args) {
ArrayDeque<Integer> ad = new ArrayDeque<>();
// add element of array
ad.add(3);
ad.add(4);
System.out.println("Add Element. content: " + ad.toString());
// add element to its first (head) & last (tail) index
ad.addFirst(1);
ad.addLast(5);
System.out.println("AddFirst & AddLast. content: "+ ad.toString());
// offers are similar to adds
ad.offer(6);
ad.offer(7);
ad.offerFirst(0);
ad.offerLast(8);
System.out.println("Offers. content: " + ad.toString());
System.out.println("Current size: " + ad.size());
// peekFirst, peek, getFirst data
System.out.println("Peek First data is " + ad.peekFirst());
System.out.println("Peek data is " + ad.peek());
System.out.println("GetFirst is " + ad.getFirst());
// peekLast, getLast data
System.out.println("Peek Last data is " + ad.peekLast());
System.out.println("GetLast is " + ad.getLast());
// polls, get data & remove from queue
System.out.println("PollFirst data is " + ad.pollFirst() + ", content: " + ad.toString() );
System.out.println("Poll data is " + ad.poll()+ ", content: " + ad.toString());
System.out.println("PollLast data is " + ad.pollLast() + ", content: " + ad.toString());
}
示例3: testOfferLastNull
import java.util.ArrayDeque; //導入方法依賴的package包/類
/**
* offerLast(null) throws NPE
*/
public void testOfferLastNull() {
ArrayDeque q = new ArrayDeque();
try {
q.offerLast(null);
shouldThrow();
} catch (NullPointerException success) {}
}