當前位置: 首頁>>代碼示例>>Java>>正文


Java ArrayDeque.offerLast方法代碼示例

本文整理匯總了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();
}
 
開發者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: 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) {}
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:ArrayDequeTest.java


注:本文中的java.util.ArrayDeque.offerLast方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。