Java Queue.offer(E e)

Syntax

Queue.offer(E e) has the following syntax.

boolean offer(E e)

Example

In the following code shows how to use Queue.offer(E e) method.


import java.util.LinkedList;
import java.util.Queue;
// w  w  w  . j a v a  2  s  . com
public class Main {
  public static void main(String[] args) {
    Queue<String> queue = new LinkedList<String>();
    queue.offer("First");
    queue.offer("Second");
    queue.offer("Third");
    queue.offer("Fourth");

    System.out.println(queue);
  }
}

The code above generates the following result.