I'm practicing what are pretty basic java array exercises and I'm having a hard time wrapping my head around how to insert an element into the beginning of an array and then shift the remaining elements to the right. So if the array hasn't gone over its max size, inserting a z in front of array, j, a, v, a would make for z, j, a, v, a.
I know how to do this with array lists, I'm just having a difficult time getting the logic correct with arrays. This is what I have so far:
public void addFront(char ch)
{
for(int i = 1; i < data.length-1; i++){
char temp = data[i - 1];
data[i] = temp;
}
data[0] = ch;
}
It seems like I need a temporary variable but I'm not using it correctly in this instance. Any input would be appreciated!
Array?