← Back to Generics
Question 183
Create a Generic Method That Repeats a Value
Create a Generic Method That Repeats a Value
Complete the generic methodrepeatValuethat takes a value and a count, then returns anArrayList<T>containing that value repeatedcounttimes. IMPORTANT: Do NOT write a main method. A hidden test will callRepeatTool.repeatValue("Hi", 3)andRepeatTool.repeatValue(4, 2)and print each resulting list.
Expected Output:
[Hi, Hi, Hi] [4, 4]
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
GenericsMethods
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.