本文整理汇总了Java中java.util.ArrayDeque.offerFirst方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayDeque.offerFirst方法的具体用法?Java ArrayDeque.offerFirst怎么用?Java ArrayDeque.offerFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.ArrayDeque
的用法示例。
在下文中一共展示了ArrayDeque.offerFirst方法的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: testOfferFirstNull
import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
* offerFirst(null) throws NPE
*/
public void testOfferFirstNull() {
ArrayDeque q = new ArrayDeque();
try {
q.offerFirst(null);
shouldThrow();
} catch (NullPointerException success) {}
}