You are viewing a single comment's thread. Return to all comments →
Scanner in = new Scanner(System.in); int numElements = Integer.parseInt(in.nextLine()); List<String> list = new ArrayList<>(Arrays.asList(in.nextLine().split(" "))); int numQueries = Integer.parseInt(in.nextLine()); IntStream.rangeClosed(1, numQueries).forEach(value -> { String operation = in.nextLine(); if ("Insert".equals(operation)) { String[] insertAt = in.nextLine().split(" "); list.add(Integer.parseInt(insertAt[0]), insertAt[1]); } else if ("Delete".equals(operation)) { int deleteAt = Integer.parseInt(in.nextLine()); list.remove(deleteAt); } }); System.out.print(String.join(" ", list));
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 →