my dog learned polymorphism*
The moose likes Beginning Java and the fly likes stacks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "stacks" Watch "stacks" New topic


Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
in my book they created a stack object like so..

Stack word = new Stack();

and they pushed and poped characters.

because the book didn't say that the Stack was a char Stack.

so you can push or pop any value in a stack?

and it doesn't matter?

so i could say

char A = a;
String string = hello;

word.push (A);
word.push (3);
word.push (string);

and i wouldn't get an error?

please clarify...



You down with OOP? Yeah you know me!
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
It shouldn't allow it, try and compile and run it.

Stack is not a stand alone data structure, it could be build on an array, linked list and in the case of Stack in the API it is built using Vector.

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
It is sorta covered in the JavaRanch Style Guide.
subject: stacks
Similar Threads
String to char.
Infix to postfix algorithm
How to assign a String as a char varable name
Printing char actually prints an int?
Character Array question