How can I insert an element (an integer for example) at the beginning of an array? I can not use the ArrayList class or anything like that, can you help me please? Thanks in advance.
This is the header of the method
public void addFirst(int newElem);
And here my class
public class ListArray{
private int size;
private int[] numeros;
public ListArray(int size){
numeros = new int[size];
for (int i=0;i<size;i++){
numeros[i]=(int)(Math.random()*10+1);
}
}
This is what I have
public void addFirst(int newElem){
int[] nuevo = new int[this.size+1];
nuevo[0]=newElem;
for (int i=1;i<nuevo.length;i++){
nuevo[i]=numeros[i];
}
}