Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

new class from old class

 
Null Void
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See
Collections.copy(List src, List dest);
and
List.addAll (Collection c);
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic