Question: Here's what the layout is

```
index   num 
0      [10]
1      [20]
2      [30]
 (Add 35 here)
3      [40] Move elements down
4      [50]
5      [60]
6      [70]

```

then my method is this

```
public static void method(int[] num, int index, int addnum)
{

}

```

How can i add 35 in there?

Tried this:

```
public static void method(int[] num, int index, int addnum)
{
int index = 10;
for(int k = num.length k>3; k++)
{
        Num[k]=num[k++]
}
    Num[3] = 35;

```

Answer: 
You need to

1. allocate a new array with room for one new element.

```
int[] newArray = new int[oldArray.length + 1];

```
2. Copy over all elements and leave room for the one to insert.

```
for (int i = 0; i < newArray.length - 1; i++)
    newArray[i < insertIndex ? i : i + 1] = oldArray[i];

```
3. Insert 35 in the empty spot.

```
newArray[insertIndex] = numberToInsert;

```

---

Note that it's **not** possible to do in a method like this:

```
public static void method(int[] num, int index, int addnum)
              ^^^^

```

since you **can't** change the length of `num`.

You *need* to allocate a new array, which means that need to *return* the new array:

```
public static int[] method(int[] num, int index, int addnum)
              ^^^^^

```

and then call the method like this:

```
myArr = method(myArr, 3, 35);

```
How about this? 

```
public class test {
public static void main(String[] arg) throws IOException
{
int[] myarray={1,2,3,5,6};//4 is missing we are going to add 4
int[] temp_myarray=myarray;//take a temp array
myarray=addElement(myarray,0);//increase length of myarray and add any value(I take 0) to the end
for(int i=0;i<myarray.length;i++)
{   if(i==3) //becaues I want to add the value 4 in 4th place
        myarray[i]=4;
    else if(i>3)
        myarray[i]=temp_myarray[i-1];
    else 
        myarray[i]=temp_myarray[i];
}
for(int i=0;i<myarray.length;i++)
    System.out.print(myarray[i]);//Print new array
}

static int[] addElement(int[] arr, int elem) {
    arr  = Arrays.copyOf(arr, arr.length + 1);
    arr[arr.length - 1] = elem;
    return arr;
}
}

```