Or using StringBuilder for efficiency:
public static String combine(String[][] arr) { StringBuilder sb = new StringBuilder(); for (int row = 0; row < arr.length; row++) { for (int col = 0; col < arr[row].length; col++) { sb.append(arr[row][col]); if (!(row == arr.length - 1 && col == arr[row].length - 1)) { sb.append(" "); } } }
def combine(arr): result = [] for row in arr: for item in row: result.append(item) return " ".join(result)