Add the following method to the ArrayIntList class from this chapter.
Write a method called stretch that takes an integer n as a parameter and that increases a list of integers by a factor of n by replacing each integer in the original list with n copies of that integer. For example, if a variable called list stores [18, 7, 4, 24, 11] and we make the call of list.stretch(3); the list should be changed to store [18, 18, 18, 7, 7, 7, 4, 4, 4, 24, 24, 24, 11, 11, 11] .
public void stretch(int n)
{
if(size * n > elementData.length)
return;
for(int i = 0; i < size; i += n)
{
int value = elementData[i];
for(int k = 1; k < n; k++)
{
for(int j = size; j >= i + k; j--)
{
elementData[j] = elementData[j - 1];
}
elementData[i + k] = value;
size++;
}
}
}