1import java.util.Scanner;
2
3public class ElemRemoval {
4
5 public static void main(String[] args) {
6 Scanner in = new Scanner(System.in);
7 int[] intArr = {1, 2, 5, 12, 7, 3, 8};
8 System.out.print("Enter Element to be deleted : ");
9 int elem = in.nextInt();
10
11 for(int i = 0; i < intArr.length; i++){
12 if(intArr[i] == elem){
13 // shifting elements
14 for(int j = i; j < intArr.length - 1; j++){
15 intArr[j] = intArr[j+1];
16 }
17 break;
18 }
19 }
20
21 System.out.println("Elements -- " );
22 for(int i = 0; i < intArr.length - 1; i++){
23 System.out.print(" " + intArr[i]);
24 }
25 }
26}
1//Make an res array that is equal to a but don't contains number 0
2int[] res = Arrays.stream(a).filter(x -> x != 0).toArray();
1//Use ArrayList XD
2import java.util.ArrayList;
3array.remove(i); //remove element by index