Question: Java Write a method named repeat that accepts an ArrayList of Strings and an integer k as parameters and that replaces each element with k
Java
Write a method named repeat that accepts an ArrayList of Strings and an integer k as parameters and that replaces each element with k copies of that element. For example, if the list stores the values ["how", "are", "you?"] before the method is called and k is 4, it should store the values ["how", "how", "how", "how", "are", "are", "are", "are", "you?", "you?", "you?", "you?"] after the method finishes executing. If k is 0 or negative, the list should be empty after the call.
Only write one method, not a whole class.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
