Java Array to String toPrettyString(String[] array)

Here you can find the source of toPrettyString(String[] array)

Description

to Pretty String

License

Open Source License

Declaration

public static String toPrettyString(String[] array) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static String toPrettyString(Map map) {
        StringBuffer buf = new StringBuffer();
        buf.append("{");
        for (Object key : map.keySet()) {
            buf.append(key.toString());/*w  ww.  j  a  v a  2  s.  co  m*/
            buf.append(" : ");

            Object val = map.get(key);
            if (val == null) {
                buf.append("null");
            } else if (val instanceof String[]) {
                buf.append(toPrettyString((String[]) val));
            } else {
                buf.append(val.toString());
            }
            buf.append(", ");
        }
        if (buf.length() > 1) {
            buf.deleteCharAt(buf.length() - 1);
            buf.deleteCharAt(buf.length() - 1);
        }
        buf.append("}");
        return buf.toString();
    }

    public static String toPrettyString(String[] array) {
        StringBuffer buf = new StringBuffer();
        buf.append("[");
        for (String st : array) {
            buf.append(st);
            buf.append(",");
        }
        if (buf.length() > 1)
            ;
        buf.deleteCharAt(buf.length() - 1);
        buf.append("]");
        return buf.toString();
    }
}

Related

  1. permChangeToString(int[] permutation)
  2. stringify(int arr[])
  3. stringify(int[] raw)
  4. toDelimitedString(Object[] array, String delimiter)
  5. toDelimitedString(Object[] array, String delimiter)
  6. toString(byte[] array)
  7. toString(Class aClass, Object[] objects)
  8. toString(Class[] modelPath)
  9. toString(final byte[] buffer, final int offset, final int length)