You can always expand an array just by increment the size of it while creating an array or you can also change the size after creating, but to shrink or delete elements. The alternate solution without creating a new array, possibly is:
package sample;
public class Delete {
int i;
int h=0;
int n=10;
int[] a;
public Delete()
{
a = new int[10];
a[0]=-1;
a[1]=-1;
a[2]=-1;
a[3]=10;
a[4]=20;
a[5]=30;
a[6]=40;
a[7]=50;
a[8]=60;
a[9]=70;
}
public void shrinkArray()
{
for(i=0;i<n;i++)
{
if(a[i]==-1)
h++;
else
break;
}
while(h>0)
{
for(i=h;i<n;i++)
{
a[i-1]=a[i];
}
h--;
n--;
}
System.out.println(n);
}
public void display()
{
for(i=0;i<n;i++)
{
System.out.println(a[i]);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Delete obj = new Delete();
obj.shrinkArray();
obj.display();
}
}
Please comment for any mistakes!!