File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes benefits Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "benefits" Watch "benefits" New topic
Author

benefits

johnathan smith
Greenhorn

Joined: Mar 30, 2007
Posts: 21
hey

just wondering if anyone could tell me the benefits of using an ArrayList as oppose to a stack or a queue etc?

thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
That is a bit like asking for the benefits of drinking wine instead of beer.

ArrayList Stack and Queue are different from one another.

ArrayList is a random-access collection; you can insert a value at point x and retrieve the value from point y. It is based on an array; you can access object no 1 and object no 1000000 in just about the same time. Object no 0 might be a bit faster; not sure.
A Queue is like a LinkedList, where the value objects form a chain; it is implemented to work in a FIFO (first in-first out) order. Just like the queue at Morrison's for the till.
A Stack works in a LIFO (last in-first out) manner; you push objects onto it and "peek" (inspect) or "pop" (remove and retrieve) whichever object was last pushed into the stack. Like a pile of plates in the kitchen; you put plates on top of the pile and take the top plate to eat from.

So you use the different collection types depending which order you want the values back.

[edit]I mistakenly said FIFO was first in last out: corrected[/edit]
[ April 23, 2007: Message edited by: Campbell Ritchie ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: benefits
 
Similar Threads
Did any one try real estate business?
JSF
dealing with an addiction
SessionFacade
Cleared SCEA, Part 1, 2 and 3