Answer:
// Method to double the content in a list
// Method receives an arraylist as parameter
public static void doubleList(ArrayList<String> stringlist) {
// Create a new array list to hold the new content
ArrayList<String> newList = new ArrayList<>();
// Create a loop that cycle through the string list
// For every cycle, get the current content of the list
// and add it twice to the new list
for (int i = 0; i < stringlist.size(); i++) {
newList.add(stringlist.get(i));
newList.add(stringlist.get(i));
}
// Copy the content of the new list back to the string list
stringlist = newList;
// Display the result
System.out.println(stringlist);
}
Step-by-step explanation:
Please go through the comments in the code for better understanding and readability.
Hope this helps!