I have an array with a size of 5, I want to delete an element from the same array which should reduce it's size by one as well, I can make it by creating a new array but I am trying to execute on the same array. Is there is any way to get make it?
public static void main(String[] args) {
// TODO Auto-generated method stub
int arraysize = 5;
int[] a = new int[arraysize] ;
a[0]=1;
a[1]=2;
a[2]=3;
a[3]=4;
a[4]=5;
for(int i=0 ; i < a.length ; i++)
{
if(a[i]==3)
{
a[i]=a[i+1];
i = i + 1;
}
System.out.println(a[i]);
}
a[arraysize] = a[arraysize-1] ;
}