Click to See Complete Forum and Search --> : Insert?


daileyps
September 18th, 2000, 11:41 AM
Any way to insert an array element and automatically push the rest of the elements down in the array? IE. similar to insertElementAt for JList?

Phill
September 18th, 2000, 02:24 PM
Hi
If you are talking about a normal array you would have to take the elements out of the array and then add them all again you the right order. So I think it would be best if you use a Stack instead. Stack has last in is the first out.

Stack s = new Stack();
s.push(Object);// adds an Object
s.pop();// takes the first Object out, which is the last object entered



If you are adding numerical values, you will have
to cast them to the appropriate wrapper class(and
cast them back again when you take them out), as
Stacks only take Objects.
Phill.