Write a method that takes 2 parameters: an ArrayList<String> list
, and an int numRepeats
representing the number of times to repeat each element in the array.
Return a new ArrayList with each element repeated numRepeats
times.
For example, if we had an ArrayList<String> list
with the values [“hello”, “world”]:
repeatElements(list, 3)
Should return a new ArrayList with the elements:
["hello", "hello", "hello", "world", "world", "world"]