Problem:
Question - Write a method called collapse, that takes in an ArrayList of Strings as a parameter and replaces each pair of strings with a single string that consists of the two initial strings in parenthesis separated by a space. If the list is odd length, the final element is stays unchanged. For examples ["hello", "bye", "plus", "minus", "girl", "boy", "smile"] the method should return ["(hello bye)", "(plus minus)". "(girl boy)", "smile"]
Write the code step by step and explain it.