This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Collection class to be used when behavior needed as LIFO  RSS feed

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Please let me know what is the Collection class we need to implement if we need the behavior as LIFO .(Last In First Out)
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the LinkedList implementation of Collection has methods addFirst, addLast, removeFirst and removeLast. I think you can use it to implement a LIFO queue.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LinkedList deafult is FIFO know , but how does addFirst , addLast can help ??

( Assume that i am getting all the data directly from the database and gettiing stored in a LinkedList)
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use one of the Deque implementations (or Stack if you're not using java 1.6). The Javadoc describes how to use them as LIFO queues.
 
Evan Caballero
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to use a LinkedList as a LIFO queue, call addFirst and removeFirst methods only ;)
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you .
 
Marshal
Posts: 58378
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joanne Neal wrote:Use one of the Deque implementations . . .

Probably ArrayDeque.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!