Java String Implode implodeParams(Object[] params)

Here you can find the source of implodeParams(Object[] params)

Description

Converts and array of objects into a concatenated string Uses the "," character as the glue

License

Apache License

Parameter

Parameter Description
params a parameter

Declaration

public static final String implodeParams(Object[] params) 

Method Source Code

//package com.java2s;
/**/* ww  w.j a  va2 s .c o m*/
 * Copyright 2012-2013 American Institute for Computing Education and Research Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *
 * You may not use this file except in compliance with the License.
 *
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Converts and array of objects into a concatenated string
     *
     * Uses the "," character as the glue
     *
     * @param params
     * @return
     */
    public static final String implodeParams(Object[] params) {
        return implodeParams(params, ",");
    }

    /**
     * Converts and array of objects into a concatenated string
     *
     * @param params
     * @param glue
     * @return
     */
    public static final String implodeParams(final Object[] params, final String glue) {

        String returnValue = "";

        if (params.length == 1) {
            return params[0].toString();
        }

        returnValue += params[0];

        for (int i = 1; i < params.length; i++) {
            returnValue += glue + params[i].toString();
        }

        return returnValue;
    }
}

Related

  1. implode(String[] segments, String delimiter)
  2. implode(String[] strings, String delimiter)
  3. implode(String[] stringsArr, String glue)
  4. implode(StringBuilder sbuf, Object[] data, String separator)
  5. implode(T[] array, String delim)
  6. implodeString(String[] strings, String seperator)
  7. implodeStringArray(String tokens[], String separator)
  8. implodeStrings(String[] strings)