wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Accessing collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Accessing collections" Watch "Accessing collections" New topic
Author

Accessing collections

Ramnath krishnamurthi
Ranch Hand

Joined: Jan 22, 2003
Posts: 56
Hi,
I was going thro the Collection Frame Work and looks like except the legacy Stack class(which is a subclass of Vector),other implementations such as TreeSet and TreeMap support FIFO(First In First Out).Correct me if am wrong.
Thanks,
Ramnath
Feed an Opportunity.Starve a Problem
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Ramnath,
Maybe you're confusing some terms. Many containers are ordered in the sense that their contents are organized in some manner. A TreeSet for instance can be ordered based on the results of "equals" being invoked on each of the items in itself. That doesn't mean that it's FIFO or FILO; it simply means that the contents are ordered a particular way. With the exception of stacks and queues and possibly dequeues, most containers will focus on ordering its contents in some algorithmically efficient manner.
The Stack class for example just provides an interface to the ArrayList class to make it act like you would expect. You can still pull any element out if that you want, thereby breaking its "stackness".
Remember that java.util has alot of different interfaces. Some of them are aimed at different ordering semantics. Set doesn't really order anything. Neither does map. List however, which Stack implements indirectly), does maintain an order from element 1 to n, where n is the size of the container -- and that is all that allows the Stack to operate like a Stack.
I'm getting wordy, so I'll leave it at that.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
 
jQuery in Action, 2nd edition
 
subject: Accessing collections