0

I'm probably going about this in the wrong way, but I have a stack of Objects, and some of these can be ArrayLists. I want to be able to pop an object that is actually an ArrayList off the stack, unbox it, add something, and then pop it back on. For example:

Stack<Object> s = new Stack<Object>();
ArrayList l = new ArrayList();
Object x;
s.Push(l);
x = s.Pop();
x = (ArrayList)x; //This is the line I don't know how to do
x.Add("Something");
s.push(x);

Does anyone have an idea of how to do what I'm trying to do?

Thanks in advance :)

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by tdeck
1

do in this way:

...............
Object x;
x = s.Pop();
ArrayList al=x as ArrayList ;
if(al!=null)
{
 al.Add("Something");
}
...............
0

Thanks, that works the way it should! Apparently what made the difference was the use of a new name for the created arrayList.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.