• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stack class in Java ?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a class in Java that can be used as a stack (push, pop) ? Or should I implements it myself with an ArrayList ?
Nicolas
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.util.Stack
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could extend a LinkedList with sort of a Fa�ade pattern. Just hide the methods you don't want.
Isn't Stack, Vector, etc. supposed to not be used?
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Isn't Stack, Vector, etc. supposed to not be used?


Where did you get that?
 
Simon Percivall
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, because Java 2 introduced replacements for the previous containers. Implementations which were better speed-wise. HashMap instead of Hashtable, ArrayList instead of Vector (, Iterator instead of Enumerator).
I haven't used any Java before 1.3, I got the "shouldn't be used" opinion from "Thinking in Java" by Bruce Eckel. So really, I don't know by own experience.
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the point is that people should master collection classes and interfaces because they make for more flexible programs than are otherwise possible. But there are places where the legacy classes, like Vector and Stack are perfectly fine. They have been upgraded to implement the Collection and List interfaces, so they can play with the Collection classes. As of 1.3, at least, they are not deprecated, and Swing seems to use them.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic