Java List to String listToString(List list, String prefix, String suffix, String separator)

Here you can find the source of listToString(List list, String prefix, String suffix, String separator)

Description

list To String

License

Open Source License

Declaration

public static String listToString(List list, 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 listToString(List list, String prefix,
            String suffix, String separator) {
        if (list == null)
            return null;
        return iteratorToString(list.iterator(), prefix, suffix, separator);
    }//w w w .ja v  a 2 s. c o  m

    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. listToString(List list)
  2. listToString(List list)
  3. listToString(List list, char sep)
  4. listToString(List list, String delim)
  5. listToString(List list, String glue)
  6. listToString(List list)
  7. listToString(List list)
  8. listToString(List list, String delim)
  9. listToString(List list, String header, String separator, String footer)