List multiplicator

Report a typo

You are provided with the backbone of the ListMultiplicator class which has a method that takes a list and repeats its contents a specified number of times. The method should change the original list contents.

Your task is to add an implementation to the method without changing its signature.

It is guaranteed that:

  • the list is not null
  • n equals or is greater than zero

n stands for the number of times the original list is repeated in the result. In case n equals zero, the resulting list should be empty.

For example, if n equals 2 and the original list is:

[1, 2, 3] 

the result should be:

[1, 2, 3, 1, 2, 3]
Write a program in Java 17
import java.util.List;

/**
Class to modify
*/
class ListMultiplicator {

/**
Repeats original list content provided number of times
@param list list to repeat
@param n times to repeat, should be zero or greater
*/
public static void multiply(List<?> list, int n) {
// Add implementation here
}
}
___

Create a free account to access the full topic