The following program guide you to delete an element at a specific position in a given array.

Deleting an element refers to removing an element from the existing list of elements in an array. To delete an element from any other location, the elements are to be moved upwards in order to fill up the location vacated by the removed elements.

After the deletion, the size of the linear array is decreased by the factor of one.

Java code to delete an element from the given array.

import java.util.Scanner;
public class Deletion
{
    public static void main(String[] args)
    {
        int[] a = new int[50];
        Scanner obj = new Scanner(System.in);
        System.out.println("enter the size of an array and elements");
        int size = obj.nextInt();
        for(int i=0; i<size; i++)
        {
            a[i] = obj.nextInt();
        }
        System.out.println("ARRAY ELEMENTS BEFORE DELETION");
        for(int i=0; i<size; i++)
        {
            System.out.println(a[i] + " ");
        }
        System.out.println("Enter the position where the element should be inserted");
        int pos = obj.nextInt();
        for(int i=pos; i<size; i++)
        {
            a[i] = a[i+1];
        }
        --size;
        System.out.println("ARRAY ELEMENTS AFTER DELETION");
        for(int i=0;i<size;i++)
        {
            System.out.println(a[i] + " ");
        }
    }
}

Output:

output :
enter the size of an array and elements
5
enter the elements of the array
2
4
6
8
10
ARRAY ELEMENTS BEFORE DELETION
2 
4 
6 
8 
10 
Enter the position where the element should be deleted
0
ARRAY ELEMENTS AFTER DELETION
4 
6 
8 
10