Here you can find the source of createTable(List
public static String createTable(List<String> datas, String[] headers, int numColumns, int cellPadding, int border)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2007 Boeing./*w w w. j av a2 s .c o m*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Boeing - initial API and implementation *******************************************************************************/ import java.util.List; public class Main { private static final String begin = "<table "; public static String createTable(List<String> datas, String[] headers, int numColumns, int cellPadding, int border) { StringBuilder table = new StringBuilder(begin); if (datas == null) { throw new IllegalArgumentException("The data can not be null"); } if (datas.size() % numColumns != 0) { throw new IllegalArgumentException( "The table could not be created becuase the data does not match the column size"); } if (border > 0) { table.append("border=\"" + border + "\""); } if (cellPadding > 0) { table.append("cellpadding=\"" + cellPadding + "\""); } table.append(">"); if (headers != null && headers.length == numColumns) { table.append("<tr>"); for (String header : headers) { table.append("<th>" + header + "</th>"); } table.append("</tr>"); } int colIndex = 0; for (String data : datas) { if (colIndex == 0) { table.append("<tr>"); } table.append("<td>" + data + "</td>"); colIndex++; if (colIndex == numColumns) { table.append("</tr>"); colIndex = 0; } } return table.toString(); } }