Here you can find the source of arrayToHTMLString(Object[] objectArray, int indent)
Parameter | Description |
---|---|
objectArray | The array to extract an HTML string of. |
indent | Indentation. |
public static String arrayToHTMLString(Object[] objectArray, int indent)
//package com.java2s; /* //from w w w. j ava2 s. c o m * This file is part of LAIS (LaSEEB Agent Interaction Simulator). * * LAIS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * LAIS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LAIS. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Indentation constant. */ public static final int INDENT = 2; public static final String spaceChar = " "; /** * Converts an array to an HTML string. Works in a recursive fashion, i.e., if the array contains * arrays, this method will format them accordingly, using a given indentation value. * * @param objectArray The array to extract an HTML string of. * @param indent Indentation. * @return An HTML string reflecting the objects contained in the array. */ public static String arrayToHTMLString(Object[] objectArray, int indent) { String value = ""; String indentString = ""; /* Determine indentation. */ for (int i = 0; i < indent; i++) indentString = indentString + spaceChar; /* Determine HTML string. */ for (int i = 0; i < objectArray.length; i++) { Object obj = objectArray[i]; if (obj.getClass().isArray()) { /* Call the method recursively if object is array. */ value = value + arrayToHTMLString((Object[]) obj, indent + INDENT); } else { /* If object is not array, proceed as usual. */ value = indentString + value + obj; if (i + 1 < objectArray.length) value = value + "<br>"; } } return value; } }