• + 1 comment

    Delete is not working

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        List<Integer> list= new ArrayList<>(n);
        for(int i=0;i<n;i++){
            list.add(scan.nextInt());
        }
        int q=scan.nextInt();
        for(int j=0;j<q;j++){
            String str=scan.nextLine();
            if(str.equalsIgnoreCase("Delete")){
                int m=scan.nextInt();
                list.remove(m);
            }  
            if(str.equalsIgnoreCase("Insert")){
                int x=scan.nextInt();
                int y=scan.nextInt();
                list.add(x, y);
            }   
        }
       list.forEach(i->{System.out.print(i+" ");});
    }
    

    }