Exercise: Array-Based Lists

Solve a task regarding a more efficient implementation of the addAll() method in array-based lists.

We'll cover the following

Task

The List method addAll(i,c) inserts all elements of the Collection, c, into the list at position i. (The add(i, x) method is a special case where c = {x}.) It is not efficient to implement addAll(i,c) by repeated calls to add(i,x). Design and implement a more efficient implementation in which there is no repeated calls to the add(i,x) method.

Samle input

The sample input will be as follows:

list: 1 2 3
list2: 4 5 6

Expected output

The expected output will be as follows:

List elements:
1
4
5
6
2
3

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy