Question: I want to implement a **Queue** of elements in android/java such that,

1. When I insert an element in that Queue, that element will start executing immediately if that is the only element in the Queue.
2. If there are other elements in the Queue, they get executed sequentially one after the other.
3. Once all the elements are executed the Queue waits for a new element to be inserted. Once the element is inserted, it will again start the execution.

What could be the best Collection to use for this scenario? Are there any default callbacks any collection provides which suffice condition 3?

One implementation I can think of is writing a method in my Queue impelementation which is something like

```
public static void executeNext() {
    Executor element = getFirst();
    if (element != null && element.doneExecuting()) {
        pop();
    }

    Executor next = getFirst();
    next.execute();
}

```

which will be called from my `Executor` class object (which is an element of my Queue) once the execution finishes

```
public void onExceutionComplete(){
    ExecutionQueue.getInstance().executeNext();
}

```

Answer: 
What you need is described in the [JavaDoc](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html). There is an implementation called SerialExecutor which might fit your problem.
Why dont you try to implement a listener, which will keep listening to the queue.

This will make sure as soon as new entries are in there, they would start getting executed.