We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.util.ArrayList;importjava.util.List;importjava.util.Scanner;publicclassJavaList{publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);intn=scanner.nextInt();// tao 1 list kieu so nguyen va dang arraylistList<Integer>list=newArrayList<>();// them cac phan tu vao listfor(inti=0;i<n;i++){list.add(scanner.nextInt());}intQueue=scanner.nextInt();scanner.nextLine();for(inti=0;i<Queue;i++){StringCommand=scanner.next();if(Command.equals("Insert")){inta=scanner.nextInt();intb=scanner.nextInt();list.add(a,b);// chen a vao vi tri b trong listarray}elseif(Command.equals("Delete")){intpos=scanner.nextInt();list.remove(pos);}}for(intnum:list){System.out.print(num+" ");}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java List
You are viewing a single comment's thread. Return to all comments →