A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/java-tutorial/util/arraydeque/java_arraydeque_add.php below:

Website Navigation


Java ArrayDeque Class: add() Method

Java ArrayDeque Class: add() MethodLast update on August 19 2022 21:50:42 (UTC/GMT +8 hours) public boolean add(E e)

The add() method is used to insert an given element at the end of this deque.

Note: This method is equivalent to addLast(E).

Package: java.util

Java Platform: Java SE 8

Syntax:

add(E e)
Parameters: Name Description e The element to add.

Return Value:

true (as specified by Collection.add(E))

Return Value Type: boolean

NullPointerException - if the specified element is nullThrows:

Pictorial Presentation

Example: Java ArrayDeque Class: add() Method

import java.util.ArrayDeque;
import java.util.Deque;
public class Main {
   public static void main(String[] args) {
       // Create an empty array deque with an initial capacity 5
      Deque<Integer> deque = new ArrayDeque<Integer>(5);

      // Use add() method to add 7 elements in the deque
      deque.add(10);
      deque.add(20);
      deque.add(30);
      deque.add(40);        
      deque.add(50);        
      deque.add(60);        
      deque.add(70);        

      // Print all the elements of deque
      for (Integer n : deque) {
         System.out.println(n);
      }
   }
}

Output:

10
20
30
40
50
60
70

Java Code Editor:

Previous:Arraydeque Class Methods Home
Next:addFirst Method




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4