I'm looking to move things around within an Array.
I want to be able to move the last item within the given Array to a spot while moving those in the current location to the right. I want it to move from the first spot to the second, etc. without replacing the item that is currently there.
ex)
a,b,c,d,e
Say I want to move to "3" - it would then become
a,b,c,e,d
I currently have the following:
public static void moveLastup(String[] stuff, int position)
{
String y = stuff[stuff.length-1];
for (int x = stuff.length-1; x > position; x--)
list[x] = list[x-1];
stuff[position] = y;
}
edit: sorry I don't think I was clear enough. What I want to be able to do is given this method, I should be able to move the last piece anywhere.
for (int pos = 0; pos < stuff.length; pos++)
{
moveLastup(list,pos);
showList(list);
}
Now when I execute this, it simply takes the last item in the next list in the for loop ex)
e,a,b,c,d
e,d,a,b,c
e,d,c,b,a
i would like it to show
e,a,b,c,d
a,e,b,c,d
a,b,e,c,d