Java Array to String toString(String[] arguments)

Here you can find the source of toString(String[] arguments)

Description

Provides a debug helper for printing out all arguments of a process for error tracking.

License

Open Source License

Parameter

Parameter Description
arguments the arguments of the process

Return

a single string with spaces between single arguments and quotation marks around arguments that contain spaces themselves.

Declaration

public static String toString(String[] arguments) 

Method Source Code

//package com.java2s;
/*/*w  w w  .  j av a 2s.  c om*/
 * Created on 28-Apr-2005 at 13:15:59.
 * 
 * Copyright (c) 2005 Robert Virkus / Enough Software
 *
 * This file is part of J2ME Polish.
 *
 * J2ME Polish 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 2 of the License, or
 * (at your option) any later version.
 * 
 * J2ME Polish 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 J2ME Polish; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 * Commercial licenses are also available, please
 * refer to the accompanying LICENSE.txt or visit
 * http://www.j2mepolish.org for details.
 */

import java.util.ArrayList;

public class Main {
    /**
     * Provides a debug helper for printing out all arguments of a process for error tracking.
     * @param arguments the arguments of the process
     * @return a single string with spaces between single arguments and quotation marks around arguments that contain spaces themselves.
     */
    public static String toString(String[] arguments) {
        StringBuffer call = new StringBuffer();
        for (int j = 0; j < arguments.length; j++) {
            String arg = arguments[j];
            if (arg.indexOf(' ') != -1) {
                call.append('"').append(arg).append('"');
            } else {
                call.append(arg);
            }
            call.append(' ');
        }
        return call.toString();
    }

    /**
     * Provides a debug helper for printing out all arguments of a process for error tracking.
     * @param arguments the arguments of the process
     * @return a single string with spaces between single arguments and quotation marks around arguments that contain spaces themselves.
     */
    public static String toString(ArrayList<String> arguments) {
        StringBuffer call = new StringBuffer();
        for (int i = 0; i < arguments.size(); i++) {
            String arg = (String) arguments.get(i);
            if (arg.indexOf(' ') != -1) {
                call.append('"').append(arg).append('"');
            } else {
                call.append(arg);
            }
            call.append(' ');
        }
        return call.toString();
    }
}

Related

  1. toString(Object[] array)
  2. toString(Object[] array)
  3. toString(Object[] objects)
  4. toString(String arrayName, T[] targets)
  5. toString(String[] args, char color1, char color2)
  6. toString(String[] array, String delimiter)
  7. toString(String[] line)
  8. toString(String[] paramNames, Object[] params)
  9. toString(T[] array)