DataTable { public DataTable mergeColumns(int c1, int c2) { DataTable result = new DataTable(getPageNumbers()); for (List<String> row : data) { List<String> newRow = new ArrayList<>(row.size() - 1); for (int c = 0; c < row.size(); c++) { if (c == c2) { } else if (c == c1) { String newValue = new StringBuilder().append(getOrEmpty(row, c1)).append(" ") .append(getOrEmpty(row, c2)).toString().trim(); newRow.add(newValue); } else { newRow.add(getOrEmpty(row, c)); } } result.addRow(newRow); } return result; } DataTable(int pageNumber);  DataTable(Collection<Integer> pageNumbers); DataTable addRow(String... dataRow); void addRow(List<String> dataRow); void addRows(List<List<String>> dataRows); List<String> headerRow(); List<String> headerRowIgnoreBlanks(); boolean hasSameHeaderAs(DataTable other); boolean hasSameHeaderBlanksIgnoredAs(DataTable other); boolean hasSameColumnCountAs(DataTable other); List<List<String>> getData(); TreeSet<Integer> getPageNumbers(); DataTable mergeWith(DataTable other); String getPagesAsString(); boolean hasData(); int getColumnsCount(); int getRowsCount(); List<String> getColumn(int c); List<String> getRow(int r); DataTable mergeColumns(int c1, int c2); void addBlankColumn(int index); @Override String toString();  }
@Test public void mergeColumns() { DataTable merged = dt.mergeColumns(1, 2); assertThat(merged.getRowsCount(), is(5)); assertThat(merged.getColumnsCount(), is(2)); assertThat(merged.getColumn(0), is(Arrays.asList("Vehicle type", "Car", "Car", "Truck", "Truck"))); assertThat(merged.getColumn(1), is(Arrays.asList("Brand", "Audi", "Mercedes", "Volvo", "DAF"))); }