manyStrings
Category: ArrayList
Author: Stuart Reges
Book Chapter: 10.1
Problem: manyStrings
Write a static method manyStrings that takes an
ArrayList of Strings and an integer n as parameters and that replaces every
String in the original list with n of that String. For example,
suppose that an ArrayList called "list" contains the following values:
("squid", "octopus")
And you make the following call:
manyStrings(list, 2);
Then list should store the following values after the call:
("squid", "squid", "octopus", "octopus")
As another example, suppose that list contains the following:
("a", "a", "b", "c")
and you make the following call:
manyStrings(list, 3);
Then list should store the following values after the call:
("a", "a", "a", "a", "a", "a", "b", "b", "b", "c", "c", "c")
You may assume that the ArrayList you are passed contains only Strings and
that the integer n is greater than 0.
Recall that the primary methods for manipulating an ArrayList are:
add(Object value) appends value at end of list
add(int index, Object value) inserts given value at given index,
shifting subsequent values right
get(int index) returns the value at given index
remove(int index) removes value at given index, shifting
subsequent values left
set(int index, Object value) replaces value at given index with
given value
size() returns the number of elements in list
Write your solution to manyStrings below.