89.8k views
2 votes
Assume the availability of an instance variable arr that refers to an ArrayList of Strings. Write a helper method concatAll that returns the concatenation of all the Strings in the ArrayList in the order in which they appear in the ArrayList

1 Answer

2 votes

Answer:

Step-by-step explanation:

The following code is written in Java and is a method that takes in an ArrayList as a parameter, it then loops through the ArrayList and adds each element to the instance variable called arr as well as a space between each element (this can be removed by deleting the " "). Finally, it prints the final result of the variable arr to the screen.

public static void concatAll(ArrayList<String> myArr) {

String arr = "";

for (int x = 0; x < myArr.size(); x++) {

arr += myArr.get(x) + " ";

}

System.out.println(arr);

}

User Ngong
by
4.4k points