• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Ravi Kiran Va
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)
 
Evan Caballero
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)
 
Joanne Neal
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 .
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:Use one of the Deque implementations . . .
Probably ArrayDeque.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!