Java Array to String arrayToString(Object[] array, String prefix, String suffix, String separator)

Here you can find the source of arrayToString(Object[] array, String prefix, String suffix, String separator)

Description

array To String

License

Open Source License

Declaration

public static String arrayToString(Object[] array, String prefix,
            String suffix, String separator) 

Method Source Code

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

import java.util.*;

public class Main {
    public static String arrayToString(Object[] array, String prefix,
            String suffix, String separator) {
        return listToString(arrayToList(array), prefix, suffix, separator);
    }/*  w  w w  . j a  va 2  s. c om*/

    public static String listToString(List list, String prefix,
            String suffix, String separator) {
        if (list == null)
            return null;
        return iteratorToString(list.iterator(), prefix, suffix, separator);
    }

    public static List arrayToList(Object[] objs) {
        if (objs == null)
            return null;
        List ret = new ArrayList(objs.length);
        for (Object obj : objs) {
            ret.add(obj);
        }
        return ret;
    }

    public static String iteratorToString(Iterator i, String prefix,
            String suffix, String separator) {
        StringBuffer sb = new StringBuffer();
        boolean first = true;
        for (; i.hasNext();) {
            if (first) {
                first = false;
            } else
                sb.append(separator);
            sb.append(prefix);
            sb.append(i.next().toString());
            sb.append(suffix);
        }
        return sb.toString();
    }
}

Related

  1. arrayToString(Object[] array)
  2. arrayToString(Object[] array)
  3. arrayToString(Object[] array)
  4. ArrayToString(Object[] array, String conv)
  5. arrayToString(Object[] array, String delim, int maxValues, boolean useBrackets)
  6. arrayToString(Object[] array, String sep)
  7. arrayToString(Object[] array, String separator)
  8. arrayToString(Object[] array, String separator)
  9. arrayToString(Object[] array, String split)