当前位置: 首页>>代码示例>>Java>>正文


Java ArrayDeque.offerFirst方法代码示例

本文整理汇总了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();
}
 
开发者ID:uber,项目名称:NullAway,代码行数:22,代码来源:NullAwayNativeModels.java

示例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());                
}
 
开发者ID:mkdika,项目名称:learnjava8,代码行数:37,代码来源:TestArrayDeque.java

示例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) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ArrayDequeTest.java


注:本文中的java.util.ArrayDeque.offerFirst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。