OnJava8-Examples/generics/SimpleQueue.java
2015-11-14 16:18:05 -08:00

15 lines
420 B
Java

// generics/SimpleQueue.java
// ©2016 MindView LLC: see Copyright.txt
// A different kind of container that is Iterable
import java.util.*;
public class SimpleQueue<T> implements Iterable<T> {
private LinkedList<T> storage = new LinkedList<>();
public void add(T t) { storage.offer(t); }
public T get() { return storage.poll(); }
@Override
public Iterator<T> iterator() {
return storage.iterator();
}
}