Code: FIFO List in Java Código: Lista FIFO en Java
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.
Filed under Filed under Headline News Headline News , How To Cómo , Java Software El software de Java , Tech Note Nota técnica | |
| |
RSS 2.0 RSS 2,0 | |
Email this Article Enviar artículo
You may also like to read También puede leer |




February 26th, 2006 at 11:04 am 26 de febrero de 2006, a las 11:04 am
A nice solution for a FIFO queue is a wrapper around a circular array. Una buena solución para una cola FIFO es un wrapper alrededor de un array circular. Removes at either end are cheap, inserts at either end are also cheap. Elimina a uno de los extremos son baratas, las inserciones en los extremos también son baratos. Memory usage is low and Object allocation is infrequent. Uso de memoria es baja y objeto de asignación es infrecuente.
February 26th, 2006 at 7:54 pm 26 de febrero de 2006, a las 7:54 pm
well.. así .. isnt fifo is actually a Queue? isn't fifo es en realidad una cola? there are plenty of Queues available in Java5. hay un montón de colas disponibles en Java5.
February 27th, 2006 at 9:07 am 27 de febrero de 2006, a las 9:07 am
You are right. Tiene usted razón. I overlooked them in 1.5. Yo les pasa por alto en el 1,5. In fact ArrayList also implements Queue. De hecho ArrayList también lleva a cabo la cola.
February 17th, 2008 at 6:14 pm 17 de febrero de 2008 a 6:14 pm
can you send me a copy of your codes in FIFO which deals with the page(s). puede enviarme una copia de sus códigos a FIFO que se ocupa de la página (s). please grant me my request..thank you.!!! por favor me conceder mi petición .. gracias.!
April 26th, 2008 at 1:41 pm 26 de abril de 2008 a 1:41 pm
You could have just used LinkedList. Usted podría haber usado LinkedList. Method add adds element to the end. Método añade añadir elemento a la final. And to retrieve element use getFirst Y para recuperar elemento uso getFirst
April 27th, 2008 at 1:21 am 27 de abril de 2008 a 1:21 am
As I said before: Como he dicho antes:
“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 ".
May 25th, 2008 at 6:39 pm 25 de mayo de 2008 a 6:39 pm
Muchas gracias! MUCHAS GRACIAS!
you’r right, it is simple and clear you'r derecho, es simple y claro