One of the common questions I hear from Java newcomers is - where is a FIFO list in Java? Una de las preguntas comunes que escuche de Java está recién llegados - donde es una lista FIFO en Java?

Java does have a FIFO list capability built-in with LinkedList and ArrayList, but they are not well advertized. Java tiene una lista FIFO capacidad built-in con LinkedList y ArrayList, pero no son así advertized.

A FIFO interface should at least have: Una interfaz FIFO debe tener al menos:

 public interface FIFO {     /** Add an object to the end of the FIFO queue */     boolean add(Object o);      /** Remove an object from the front of the FIFO queue */     Object remove();      /** Return the number of elements in the FIFO queue */     int size(); } Interfaz pública FIFO (/ ** Añade un objeto al final de la cola FIFO * / boolean añadir (Object o); / ** Eliminar un objeto desde la parte delantera de la cola FIFO * / Object remove (); / ** Volver el número de elementos en la cola FIFO * / int size ();) 

A FIFOList class implementing the above would simply be: Una clase FIFOList la aplicación de lo anterior sería simplemente:

 public class FIFOList extends LinkedList implements FIFO {     public Object remove() {         return remove(0);     } } FIFOList público de clase se extiende LinkedList implementa FIFO (public Object eliminar () (retorno eliminar (0);)) 

I prefer this setup instead of using a LinkedList.remove(0) directly. Yo prefiero esta configuración en lugar de utilizar un LinkedList.remove (0) directamente. It looks cleaner. Se ve más limpio.

BTW: You can also extend an ArrayList instead of LinkedList to achieve the same functionality. BTW: Usted también puede extender una ArrayList en lugar de LinkedList para lograr la misma funcionalidad. LinkedList should in theory provide better performance. LinkedList debería, en teoría, proporcionar un mejor rendimiento.