Java Array Convert to arrayToHTMLString(Object[] objectArray, int indent)

Here you can find the source of arrayToHTMLString(Object[] objectArray, int indent)

Description

Converts an array to an HTML string.

License

Open Source License

Parameter

Parameter Description
objectArray The array to extract an HTML string of.
indent Indentation.

Return

An HTML string reflecting the objects contained in the array.

Declaration

public static String arrayToHTMLString(Object[] objectArray, int indent) 

Method Source Code

//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 = "&nbsp;";

    /**
     * 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;
    }
}

Related

  1. arrayOfIntToString(int[] array)
  2. arrayOfValuesToLookForIsEmpty()
  3. arrayToCamelCase(String[] nameArray, int start, int end)
  4. arrayToCSL(String[] vals)
  5. arrayToDouble(final byte[] array, final int start)
  6. arrayToInt(final byte[] array, final int start)
  7. arrayToJava(double[] v, int off, int len, String name)
  8. arrayToJson(int[] x)
  9. arrayToLine(Object[] source)