my dog learned polymorphism*
The moose likes Java in General and the fly likes Object on stack Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Object on stack" Watch "Object on stack" New topic
Author

Object on stack

Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Hi,
How to put an object on stack in java?
Rgds,
Seetesh
Annekee Dufour
Ranch Hand

Joined: Nov 04, 2003
Posts: 41
why would you want to do that?
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Hi,
Just checking out the possiblity if its possible?
Seetesh
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Hi,
I was trying something like this
String language = "english";
String country = "english";
int a = 100;
int b= 100;
Stack astack = new Stack();
astack.push(language);
Stacks dont seem to take in int values.
Any clues.
Seetesh
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
No, they only hold Objects. In order to push ints or other built-in types onto a stack, you need to use the wrapper classes such as Integer. You should learn as much as you can about the wrapper classes. They are used quite frequently. I'm sure you can search the board for previous discussions about them.
Layne


Java API Documentation
The Java Tutorial
Annekee Dufour
Ranch Hand

Joined: Nov 04, 2003
Posts: 41
Aha, you mean a Stack and not the stack as in stack vs. heap!
 
wood burning stoves
 
subject: Object on stack