Java String Array to String array2string(String[] s)

Here you can find the source of array2string(String[] s)

Description

Serialize a string array into a single string.

License

LGPL

Parameter

Parameter Description
s The array to be serialized

Return

A string containing the serialized version of the array

Declaration

public static String array2string(String[] s) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    private static final String STARTTAG = "|s|";
    private static final String ENDTAG = "|/s|";

    /**/*from  w ww  .j a v  a2 s.  c  o  m*/
     * Serialize a string array into a single string.
     * This method uses <code>STARTTAG</code> and <code>ENDTAG</code> to
     * serialize single entries of a string array into one string.
     *
     * @param s The array to be serialized
     * @return A string containing the serialized version of the array
     */
    public static String array2string(String[] s) {
        StringBuffer buf = new StringBuffer();

        if (s == null) {
            return "";
        }

        for (int i = 0; i < s.length; i++) {
            buf.append(STARTTAG);
            buf.append(s[i]);
            buf.append(ENDTAG);
        }

        return buf.toString();
    }
}

Related

  1. arr2str(String[] arr)
  2. arr2str(String[] arr, String sep)
  3. array2str(String[] array, String delim)
  4. array2str(String[] arrayname, int length)
  5. array2string(String array[])
  6. arrayAsString(String[] haystack)
  7. arrayAsString(String[] stringArray)
  8. ArrayCombine(String[] array, String delimiter)
  9. arrayStringToArrayInt(final String[] as)