How would you declare a String stack?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thatos
    New Member
    • Aug 2007
    • 105

    How would you declare a String stack?

    I was asked the above question, is there any other way to answer that queation besides the one which i have below.
    Code:
    Stack s  = new Stack;
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by thatos
    I was asked the above question, is there any other way to answer that queation besides the one which i have below.
    Code:
    Stack s  = new Stack;
    Use Java's generics:

    [code=java]
    Stack<String> s = new Stack<String>() ;
    [/code]

    kind regards,

    Jos

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Stack is "Vector-era" class. From it's API

      Originally posted by API
      A more complete and consistent set of LIFO stack operations is provided by the Deque interface and its implementations , which should be used in preference to this class. For example:
      [CODE=Java]Deque<Integer> stack = new ArrayDeque<Inte ger>();[/CODE]

      Comment

      Working...