• Post Reply Bookmark Topic Watch Topic
  • New Topic

Collections.asLifoQueue  RSS feed

 
Mohana Avu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to convert the ArrayDeque to a LifoQueue so that when I remove an element the last element is removed first. But it doesn't seem to work that way. Below is the code snippet


I was expecting d1.remove() to remove Z first but it removed Y - any clarifications will be helpful.
 
Dipta P Banerjee
Greenhorn
Posts: 11
Android Java Scala
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are adding the values before converting it to LIFO. Add it after converted it to Lifo to the d1 reference. For example:

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Mohana.

In the future, while posting code, please UseCodeTags (<=link; click to view) I have added them this time for you. As you can see the tags make the code much more easier to read and understand.
 
Mohana Avu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dipta, I converted the queue and then added the items. It worked as you said.
Thanks Maneesh, will use the tag as mentioned.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!