This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes new class from old class 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 "new class from old class" Watch "new class from old class" New topic
Author

new class from old class

Null Void
Greenhorn

Joined: Oct 28, 2002
Posts: 1
I have a Stack object and I want to make another instance of a Stack object but with the same values as the existing one, how do I do this?
the Stack object does not support a constructor so is there an easy way?
Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88
I haven't tried this, but I assume you can use the clone() method from Vector, which is the super class of Stack.
Otherwise, you can always call toArray() and add the elements to the new Stack one by one in a for loop.
Bill
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
See
Collections.copy(List src, List dest);
and
List.addAll (Collection c);


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Null Void
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!


Dave
 
jQuery in Action, 2nd edition
 
subject: new class from old class
 
Similar Threads
Where do static variables (class variables) live (scope)?
Stack & heap for Static methods
a question about this code
Saving contents of Stack using Object Serialization
Struts 2 newbie confused by value stack