Try to use Arrays class... if you need to peek, take last element from Object array, to remove just delete last one:
class Queue {
private Object[] mElements = new Object[] {};
public void enqueue(Object element) {
Arrays.insertAt(mElements, element, 0);
}
public Object dequeue() {
Object result = null;
if (null != mElements && 0 < mElements.length) {
result = mElements[mElements.length - 1];
Arrays.remove(mElements, result);
}
return result;
}
public Object peek() {
if (null != mElements && 0 < mElements.length)
return mElements[mElements.length - 1];
else
return null;
}
public void remove() {
if (null != mElements && 0 < mElements.length)
Arrays.remove(mElements, peek());
}
}
Using example:
class Scr extends MainScreen {
public Scr() {
Queue queue = new Queue();
queue.enqueue(new String("3"));
queue.enqueue(new Boolean(true));
queue.enqueue(new Integer(1));
//see "3" in console
System.out.println(queue.peek());
//see "3" still there
System.out.println(queue.peek());
//remove "3"
queue.remove();
//see "true" in console
System.out.println(queue.peek());
//dequeue all elements
Object element = null;
while ((element = queue.dequeue()) != null) {
System.out.println(element.toString());
}
}
}