Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing collections

 
Ramnath krishnamurthi
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic